decimals to hex

This is a discussion on decimals to hex within the C Programming forums, part of the General Programming Boards category; could anybody please tell me how to convert 0.00001 to hexadecimal value. thanx in advance...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    33

    decimals to hex

    could anybody please tell me how to convert 0.00001 to hexadecimal value.

    thanx in advance

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    You gotta be kidding. The name of the topic just below this one, when I saw this was :
    "hex to dec in c"

    You'll find your answer there : hex to dec in c
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, this is NOT the same question as the other post.

    There are two ways to look at this:
    First, you could be just wanting to write the number as a hexadecimal representation of the number:
    Hexadecimal representation of floating point (or fractions of) numbers is pretty much the same principle as decimal ones, you have to divide by one base and multiply by the other, taking a portion off at a time. But I don't REALLY see the point (aside from as a "fun excercise" [if you like that sort of thing]), because there is really no practical use of hex "floats". Hex is used to represent integer values because it's a practical way to describe the binary value without writing a whole lot of digit (8 vs 32). Unless you are really skilled in "decimal to binary", you won't be able to say which bits are in decimal number 4711, but with a little bit of practice, you can quite easily convert 1267 into 0001001001100111 (that's 4711 if you convert it back to decimal). But fractions or floating point numbers don't have a practical application in hex.

    Second option:
    You could be wanting to write the hexadecimal representation of the floating point number as a 32-bit value from memory. This would involve taking the address of the float and cast the resulting pointer to an integer-type, then print the integer as hex. This can be useful if you have a memory dump of something that is floating point, or some such thing. Not very practical for much else...

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 05:37 AM
  2. Hex Editing help and information please...
    By SG57 in forum C Programming
    Replies: 9
    Last Post: 06-25-2006, 12:30 AM
  3. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  4. Replies: 3
    Last Post: 01-23-2006, 06:25 PM
  5. Is binary HEX?
    By Budgiekarl in forum Tech Board
    Replies: 11
    Last Post: 11-23-2003, 08:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21