简体   繁体   中英

Convert integer to byte

I have program in C#. I want to convert an int to HEX and after that convert it to a byte. But there is a problem in the 3rd line:

int i = 10;
string str = i.ToString("X");
byte b = Convert.ToByte(str);

Please help me.

byte b = byte.Parse(str, NumberStyles.AllowHexSpecifier);
byte b = Convert.ToByte(str, 16);
    uint ui = 0;
    ui = checked((uint)System.Convert.ToUInt32("10"));
    Console.WriteLine(String.Format("{0:x2}", ui));

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM