int - hex conversion question

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

I guess it should be a piece of cake,
how do you convert an int to a hex value?
Thanks,
Adrian
 
Adrian said:
I guess it should be a piece of cake,
how do you convert an int to a hex value?
Thanks,
Adrian

int i=10;
string s = i.ToString("x"); // "a"
s = i.ToString("X"); // "A"
s = i.ToString("X2"); // "0A"
s = i.ToString("X4"); // "0000A"


Hans Kesting
 
Great, thanks.
Adrian

Hans Kesting said:
int i=10;
string s = i.ToString("x"); // "a"
s = i.ToString("X"); // "A"
s = i.ToString("X2"); // "0A"
s = i.ToString("X4"); // "0000A"


Hans Kesting
 
Adrian said:
I guess it should be a piece of cake,
how do you convert an int to a hex value?
Thanks,
Adrian

int intDec = 255;
string strHex = String.Format("{0:x2}",
(uint)System.Convert.ToUInt32(intDec));
 
Mark Rae said:
int intDec = 255;
string strHex = String.Format("{0:x2}",
(uint)System.Convert.ToUInt32(intDec));
This is more complicated than what Hans
suggested, wouldn't you agree?
 
Back
Top