Thread: convert 4 bits Hex to decimal

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    convert 4 bits Hex to decimal

    how to convert 4 bits in hexadecimal to decimal ?
    example :
    Code:
    11A2A311
    result :
    Code:
     295874833
    Thanks

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    what do you mean "4bits in hexadecimal"?

    0x11A2A311 in decimal is 295871249, not 295874833, so I don't really understand your question.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    2
    0x11A2A311 in decimal is 295871249, not 295874833
    yes,
    what do you mean "4bits in hexadecimal"?
    Code:
    HEX(11A2A311) equal 295871249 in DECIMAL
    Thanks

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    So, you still haven't clarified what you mean by "4 bits in hexadecimal"?

    Do you just want to convert a hexadecimal string to decimal? I'm going to assume that. If so, the easiest way is to use sscanf with a %x format specifier into an int then printf the int with %d.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    FYI, 0x11A2A311 won't fit in 4 bits. 0xF is the largest number you can fit into 4 bits. Maybe you meant 4 bytes?
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDLKey to ASCII without unicode support?
    By zacs7 in forum Game Programming
    Replies: 6
    Last Post: 10-07-2007, 03:03 AM
  2. function to convert hex to decimal
    By Moony in forum C Programming
    Replies: 5
    Last Post: 07-11-2006, 03:14 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:14 AM
  5. convert a decimal int to hex
    By pinkcheese in forum C++ Programming
    Replies: 12
    Last Post: 08-12-2002, 09:15 PM