How can I convert this string into a byte?
string a = "0x2B";
I tried this code, (byte)(a); but it said:
Cannot convert type string to byte…
And when I tried this code, Convert.ToByte(a); and this byte.Parse(a);, it said:
Input string was not in a correct format…
What is the proper code for this?
But when I am declaring it for example in an array, it is acceptable…
For example:
byte[] d = new byte[1] = {0x2a};
You have to specify the base to use in
Convert.ToBytesince your input string contains a hex number: