Mirage Source http://www.miragesource.net/forums/ |
|
Explain This Code http://www.miragesource.net/forums/viewtopic.php?f=201&t=680 |
Page 1 of 1 |
Author: | William [ Sun Oct 22, 2006 10:58 pm ] |
Post subject: | Explain This Code |
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 |
Author: | grimsk8ter11 [ Mon Oct 23, 2006 2:16 am ] |
Post subject: | |
the function names explain themselves one converts to binary, one converts from binary |
Author: | William [ Mon Oct 23, 2006 6:30 am ] |
Post subject: | |
Hmm, interesting. Then it was as I thought. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |