Decimal convert

This is a discussion on Decimal convert within the C Programming forums, part of the General Programming Boards category; I need to convert decimal to IEEE 32- floating point for a couple homework problems by hand. I was wondering ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    16

    Decimal convert

    I need to convert decimal to IEEE 32- floating point for a couple homework problems by hand. I was wondering if my answers were correct.


    13.5 is 0 0011011 00000000 00000000 00000000
    -65.125 is 1 1000001 00010000 00000000 00000000

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you convert them "not by hand" and see if they are what you expect them to be?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    16
    Quote Originally Posted by quzah View Post
    Why don't you convert them "not by hand" and see if they are what you expect them to be?


    Quzah.
    I would but do not know what to use/how to do so.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    29

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    The exponent is 8 bits, not 7 and you don't store the value of the integral part in the exponent. How do you expect to store the number 500?
    Go back to study scientific notation a little more to refresh your memory of how that is represented. It's the same thing here except that this is base 2.

    I'll use a different example, 11.25.
    First write the number in binary:
    11.25 is:
    8 + 0 + 2 + 1 + 0 + 0.25 =
    1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 + 0*2^-1 + 1*2^-2 =
    1011.01
    Now count how many times you have to move the decimal place to the left to move it to straight after the first digit:
    101.101 = 1 time
    10.1101 = 2 times
    1.01101 = 3 times (so our exponent is 3)
    What's left after the dot is the significand.
    Now:
    First bit = 0 because the number is positive.
    We need to bias our exponent by 127 because that's the bias for a float. So our exponent becomes 127 + 3 = 130, and 130 in 8 binary bits is 10000010
    Then comes our significand, which we pad with zeros to make it up to 23 bits:
    01101000000000000000000
    Then you put that together:
    01000001 00110100 00000000 00000000
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

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, 10:59 PM
  3. how to convert decimal to hexa decimal in C/
    By kalamram in forum C Programming
    Replies: 4
    Last Post: 09-03-2007, 07:39 AM
  4. convert 4 bits Hex to decimal
    By demo2000 in forum C Programming
    Replies: 4
    Last Post: 12-12-2005, 09:44 AM
  5. Replies: 10
    Last Post: 08-17-2005, 11:17 PM

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