int - hex conversion question

A

Adrian

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

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 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
 
A

Adrian

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
 
M

Mark Rae

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));
 
A

Adrian

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top