2
$\begingroup$

The question asks for the decimal number that 0x0C000000 represents if it is a floating number. I'm not too sure on how to approach this, but here's my thought process:

0x0C000000 = 0000 1100 0000 0000 0000 0000 0000 0000

The first digit is 0, so it's positive. The exponent is 0x0C = 12 - 127 = -116. The mantissa is 0x0C0000 = 12 * 16 ^ -2 = 0.046875, so the final answer is 1.046874 * 2 ^ -116. While my book has similar examples that I tried to follow along with, none were exactly of this type, so I highly suspect I'm doing something wrong. Any tips, hints, or strategies would be greatly appreciated.

$\endgroup$
  • $\begingroup$ Why the votes to close as "off-topic"? William Kahan was given the Turing award in 1989 specifically because of his work on developing IEEE-754, which is "a specification for a computing environment in which hardware, compilers and application programs would interact". It's hard to imagine something more on-topic than that. $\endgroup$ – Wandering Logic Oct 2 '15 at 1:48
  • 1
    $\begingroup$ Your question already includes a complete answer to the original problem but no question about this answer. Thus, only "yes/no" answers may remain, helping neither you nor future visitors. Please read related meta discussions here and here and adjust your question accordingly, e.g. by formulating a specific question about a single element of your answer you are uncertain about. $\endgroup$ – David Richerby Oct 2 '15 at 7:34
3
$\begingroup$

A good start is to expand the hex representation into binary like how you did it.

0000 1100 0000 0000 0000 0000 0000 0000

Then parse the word:

  • the left-most bit is the sign bit
  • the next 8 bits represent the biased-exponent
  • the last bits represent the fractional part with the "hidden one"

0 | 00011000 | 00000000000000000000000

Then, follow:

  • s represents the sign bit
  • evaluate the binary representation of the exponent to decimal
  • subtract the bias from the exponent (bias for single-precision is 127 and 1023 for double-precision)
  • evaluate the normalized form to decimal and you have your floating point decimal number

I hope this helps. It took me a while to understand encoding and decoding using IEEE-754. Slow and steady wins the race.

$\endgroup$
  • $\begingroup$ Thanks so much! So (-1) ^ 0 * (1 + 0) * 2 ^ (24 - 127) = 2 ^ -103 would be the correct single-precision floating point number? $\endgroup$ – user40496 Oct 2 '15 at 0:59
  • $\begingroup$ Yeah, you'll eventually get the floating point number: expand 1.0 x 2 ^ -103 in binary then convert to decimal. Note the fraction part is (1 + .0), not (1 + 0). This would be a common pitfall. Hence you get 1.0 x 2 ^ -103 $\endgroup$ – Joseph R. Oct 2 '15 at 2:36
  • $\begingroup$ @user40496 in your work, you used some of the bits twice. There's only one C in the whole thing, so "the exponent is 0C and the mantissa is 0C0000" couldn't possibly be right. :) $\endgroup$ – hobbs Oct 14 '15 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.