I found this searching for byte array packets. url:
http://www.codeproject.com/useritems/UD ... Server.asp
Code:
Public Function UnBinNum(ByRef S$, Optional ByVal EatOut As Boolean = True) As Integer
'MsgBox("CALL FOR UNBIN NUM:" & S$)
Dim l As Int16
Dim nval As Long
Dim h As String
'On Error GoTo Error
If Asc(Left(S$, 1)) < 249 Then
nval = Asc(Left(S$, 1))
If EatOut = True Then S$ = Right$(S$, Len(S$) - 1)
Else
l = Asc(Left$(S$, 1)) - 248
h = Mid$(S$, 2, l)
If Len(S$) < l + 1 Then nval = -1 : GoTo ErrorS
'Debug.Print "len: " & l
'Debug.Print "hex:" & h
'Debug.Print "unhex:" & HexToDecimal(h)
nval = HexToDecimal(h)
If EatOut = True Then S$ = Right$(S$, Len(S$) - l - 1)
End If
ErrorS:
'MsgBox("nval:" & nval)
Return CInt(nval)
End Function
Code:
Function BinNum(ByVal NUM) As String
Dim h As String, l As Byte
If NUM > 248 Then
h = Hex(NUM)
l = Len(h) + 248
If l > 255 Then MsgBox("L:" & l & "...." & h & "..." & Len(h))
Return (Chr(l) & h)
Else
Return (Chr(NUM))
End If
End Function