Skip to content

Commit

Permalink
add ByteArray To String Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoulJacobs committed Mar 24, 2022
1 parent c852e21 commit 5fa2149
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions M_omByteArrayFunctions.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Option Compare Database
Option Explicit

Public Function ByteArrayToHexString(ba() As Byte) As String
Dim i As Long
Dim s As String

For i = 0 To UBound(ba)
s = s & Right("00" & Hex$(ba(i)), 2)
Next
ByteArrayToHexString = "0x" & s
End Function
Public Function ByteArrayToString(ba() As Byte) As LongLong
Dim i As Long
Dim s As Double

For i = 0 To UBound(ba)
s = s * 256 + ba(i)
Next
ByteArrayToString = s
End Function

Public Sub ByteArrayToHexString_Test()
Debug.Print ByteArrayToHexString(RandomByteArray(4))
End Sub
Public Sub ByteArrayToString_Test()
Debug.Print ByteArrayToString(RandomByteArray(8))
End Sub

Private Function RandomByteArray(ByVal arrayLength As Integer) As Byte()
' Demo/helper function to create random byte array
Dim retVal() As Byte, i As Integer
Randomize
ReDim retVal(arrayLength - 1)
For i = 0 To arrayLength - 1
retVal(i) = CByte(Rnd() * 255)
Next i
RandomByteArray = retVal
End Function

0 comments on commit 5fa2149

Please sign in to comment.