# how to convert decimal to hexa decimal in C/

• 09-02-2007
kalamram
how to convert decimal to hexa decimal in C/
hello friend,

how to convert decimal to hexa decimal i c.

if possible, give me example program.
• 09-02-2007
MacGyver
If you just want to print an int in hexadecimal format, then use &#37;x or %X as the format specifier.
• 09-03-2007
kalamram
Decimal to Hex convertion.
Quote:

Originally Posted by MacGyver
If you just want to print an int in hexadecimal format, then use %x or %X as the format specifier.

I want to convert decimal to hexa decimal and ned to store one variable..

if possible give me program for this.
• 09-03-2007
QuantumPete
Quote:

Originally Posted by kalamram
if possible give me program for this.

Yeah well, we don't do your homework for you!

Besides, hexadecimal format is a way of *displaying* a number. When you declare an int for example, the number is stored in binary, when you print it out it's explicitly converted to decimal. What I'm trying to say is that you can't store a hexadecimal number.
Unless you're trying to convert a number into a string, which holds the hexadecimal representation, in that case I'd scour previous threads on this forum.

QuantumPete
• 09-03-2007
Tommo
If you don't know how to do it away from a computer, I suggest you get reading. It's pretty simple stuff:

Code:

```To convert a number from base n to 10: eg) say the number is 12345 where n >= 6    (key n^{4} = n to the power of 4)   answer: (5 x n^{0}) + (4 x n^{1}) + (3 x n^{2}) + (2 x n^{3}) + (1 x n^{4})```