I have a byte array that contains a collection of 2 byte hexadecimal numbers separated by ','. How could it be split by ',' and then the numbers be converted to integers?
The byte array contains values in ascii format.
edit: Example
My valid character range is 0 to 9 ,A to F and comma so my stream should look like
70, 67, 65, 57, 44, 55, 68, 66, 53, 44....
this would be equivalent to hexadecimal
FCA9 and 7DB5
If your byte array is truly ASCII encoded (ONE byte per character), then the following would work:
int[] ints = Encoding.ASCII.GetString(asciiEncodedBytes).Split(',')
.Select(x => Convert.ToInt32(x,16)).ToArray();
This will handle mixed case and variable length hex numbers, too.
I would convert the byte array to string and then use String.Split(',')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With