In this brief code I show a method of conversion from string of hex data to array of bytes.

input string: shex = “00010A”
return: array of bytes 0,1,10

 Private Function HexStringToByteArray(ByVal shex As String) As Byte()
        Dim B As Byte() = Enumerable.Range(0, hex.Length).Where(Function(x) x Mod 2 = 0).[Select](Function(x) Convert.ToByte(hex.Substring(x, 2), 16)).ToArray()
        Return Enumerable.Range(0, hex.Length).Where(Function(x) x Mod 2 = 0).[Select](Function(x) Convert.ToByte(hex.Substring(x, 2), 16)).ToArray()
    End Function
Advertisements