Thread: hexadecimal

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    hexadecimal

    I have to write a function to convert a float number to hexadecimal. The problem is I don't know how to convert a float number to hexadecimal although I can convert integers. Can anyone help?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    29
    To convert from decimal to hex (as far as I remember) you keep dividing the quotent by 16 and save the remainder until you get to Zero. You then read the result from the bottom up. Now you divide the remainder(after the decimal point) by 16 and save the remainder until you get to Zero. This you read from the top down.
    EG
    159.62decimal =
    159/16 = 9 r 15 = F
    9/16 = 0 r 9 = 9
    read up therefor 159 = 9F in hex
    now
    62/16 = 3 r 14 = E
    3/16=0 r 9
    read down therefor 62 = E 9
    Therefore 159.62 decimal = 9F.E9 hex

    THis is how you convert decimal to binary and i think that this applies to any base.
    Colin

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Or you could just do the following:

    cout<<hex<<number;




Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-02-2007, 05:55 AM
  2. hexadecimal to ascii
    By jpablo in forum C Programming
    Replies: 2
    Last Post: 04-12-2006, 05:28 PM
  3. would you explain to me? hexadecimal to decimal
    By shteo83 in forum C Programming
    Replies: 2
    Last Post: 02-25-2006, 03:55 PM
  4. Converting Float to Hexadecimal
    By denizengt in forum C Programming
    Replies: 3
    Last Post: 09-28-2003, 06:11 PM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM