0

So, as the title states, I am trying to convert a string into a byte array.

So, I have this string: string bytes = "2C 2D 3B 27", and I want to convert it from a string, to a byte array, without actually converting the strings contents to a byte array.

So, turn this: string bytes = "2C 2D 3B 27"

to this: byte[] byteArray = { \x2C, \x2D, \x3B, \x27 }.

1 Answers1

2
var bytes = "2C 2D 3B 27";
var byteArray = bytes.Split(' ').Select(x => int.Parse(x, System.Globalization.NumberStyles.HexNumber));
Han
  • 3,052
  • 2
  • 22
  • 31