I'm trying to convert this string array to byte array.
string[] _str= { "01", "02", "03", "FF"};
to byte[] _Byte = { 0x1, 0x2, 0x3, 0xFF};
I have tried the following code, but it does not work.
_Byte = Array.ConvertAll(_str, Byte.Parse);
And also, it would be much better if I could convert the following code directly to the byte array :
string s = "00 02 03 FF"
to byte[] _Byte = { 0x1, 0x2, 0x3, 0xFF};
Best Answer
This should work:
using
Convert.ToByte
, you can specify the base from which to convert, which, in your case, is 16.If you have a string separating the values with spaces, you can use
String.Split
to split it: