Integer to Hex

G

Guest

Hi,
I want to convert an integer (actuallu the ascii value of a character) to its equivalent Hex value. Can someone suggest, which is the easiest way to do it.

Thanks in advance,
Al.
 
F

Floyd Burger

String.Format( "{0:X2}", intValue)

--
Floyd Burger

Al Sav said:
Hi,
I want to convert an integer (actuallu the ascii value of a character) to
its equivalent Hex value. Can someone suggest, which is the easiest way to
do it.
 
P

Paul Qualls

Al,

Try something like

string hexString = String.Format("{0:x2}", intVal);

Paul Qualls

Al Sav said:
Hi,
I want to convert an integer (actuallu the ascii value of a character) to
its equivalent Hex value. Can someone suggest, which is the easiest way to
do it.
 
G

george r smith

for (int i = 0; i < 16; i++)
Console.WriteLine(Convert.ToString(i,16));

Al Sav said:
Hi,
I want to convert an integer (actuallu the ascii value of a character) to
its equivalent Hex value. Can someone suggest, which is the easiest way to
do it.
 
B

Beeeeeves

string.Format("0x{0:x}", i)
??




Al Sav said:
Hi,
I want to convert an integer (actuallu the ascii value of a character) to
its equivalent Hex value. Can someone suggest, which is the easiest way to
do it.
 
G

Guest

Thanks for all the response and different methods.

I ended up using this:
((int) c).ToString("x")

c is a char.

I am surprised to see so many different solutions, whereas I was trying so hard to find a solution.
Alwin S.
 

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

Top