01.
#Region "HexToByte"
02.
03.
Public
Function
HexToByte(
ByVal
msg
As
String
)
As
Byte
()
04.
If
msg.Length
Mod
2 = 0
Then
05.
_msg = msg
06.
_msg = msg.Replace(
" "
,
""
)
07.
Dim
comBuffer
As
Byte
() =
New
Byte
(_msg.Length / 2 - 1) {}
08.
For
i
As
Integer
= 0
To
_msg.Length - 1
Step
2
09.
comBuffer(i / 2) =
CByte
(Convert.ToByte(_msg.Substring(i, 2), 16))
10.
Next
11.
write =
True
12.
Return
comBuffer
13.
Else
14.
Return
Nothing
15.
End
If
16.
End
Function
17.
#End Region
18.
19.
#Region "ByteToHex"
20.
21.
Public
Function
ByteToHex(
ByVal
comByte
As
Byte
())
As
String
22.
Dim
builder
As
New
StringBuilder(comByte.Length * 3)
23.
For
Each
data
As
Byte
In
comByte
24.
builder.Append(Convert.ToString(data, 16).PadLeft(2,
"0"
c).PadRight(3,
" "
c))
25.
Next
26.
Return
builder.ToString().ToUpper()
27.
End
Function
28.
#End Region