tags:

views:

139

answers:

3

Hi there. 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.

+6  A: 
byte b = byte.Parse(str, NumberStyles.AllowHexSpecifier);
James Curran
A: 
byte b = Convert.ToByte(str, 16);
Bobby
no dint wanna it i wanna save 0xa in byte how can i do it?
Mehdi
A: 
    uint ui = 0;
    ui = checked((uint)System.Convert.ToUInt32("10"));
    Console.WriteLine(String.Format("{0:x2}", ui));
Faisal