Thread: how to convert decimal to hexa decimal in C/

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    14

    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.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If you just want to print an int in hexadecimal format, then use %x or %X as the format specifier.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    14

    Decimal to Hex convertion.

    Quote Originally Posted by MacGyver View Post
    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.

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by kalamram View Post
    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
    Last edited by QuantumPete; 09-03-2007 at 03:50 AM. Reason: added quote
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101
    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})

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert from Single to Decimal
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-11-2008, 06:13 AM
  2. Convert DegMinSec to Decimal Degrees
    By JacquesLeJock in forum C Programming
    Replies: 3
    Last Post: 11-21-2007, 11:59 PM
  3. how to convert decimal number to ASCII code?
    By oie in forum C Programming
    Replies: 11
    Last Post: 11-03-2006, 06:19 PM
  4. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  5. convert a decimal int to hex
    By pinkcheese in forum C++ Programming
    Replies: 12
    Last Post: 08-12-2002, 09:15 PM