I have seen many questions regarding this conversion,but neither worked for me.
I have a string with value as
string i=10;
I need to convert the string to byte as 0x10
I tried
Encoding.Unicode.GetBytes(i);
It doesn't worked. Please help
You can convert from string
to byte
using the Convert
class. It allows you to specify a base as second parameter.
So if you want to convert a hexadecimal string to byte, you can use this:
string i = "10";
Convert.ToByte(i, 16) // => 16
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.