Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Hexidecimal string to a Byte Array?

I have a string representing a hexidecimal value: "46-C9-08-B6-E8-F3-47-CF-53-2A-77-02-C9-19-7F"

I want to convert this to a byte array so it looks something like this: {&H46, &HC9, &H8, &HB6, &HE8, &HF3, &H47, &HCF, &H53, &H2A, &H77, &H2, &HC9, &H19, &H7F}

How do I do this?

like image 827
user2089227 Avatar asked Oct 22 '25 04:10

user2089227


1 Answers

Split the string and parse the hexadecimal numbers:

Dim bytes As Byte() = input.Split("-"c).Select(Function(n) Convert.ToByte(Convert.ToInt32(n, 16))).ToArray()
like image 194
Guffa Avatar answered Oct 25 '25 09:10

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!