jlee
jlee

Reputation: 3175

Floating point conversion - Binary -> decimal

Here's the number I'm working on

1 01110 001 = ____
1 sign bit, 5 exp bits, 3 fraction bits
bias = 15

Here's my current process, hopefully you can tell me where I'm missing something

  1. Convert binary exponent to decimal
    01110 = 14
  2. Subtract bias
    14 - 15 = -1
  3. Multiply fraction bits by result
    0.001 * 2^-1 = 0.0001
  4. Convert to decimal
    .0001 = 1/16

The sign bit is 1 so my result is -1/16, however the given answer is -9/16. Would anyone mind explaining where the extra 8 in the fraction is coming from?

Upvotes: 1

Views: 310

Answers (2)

Darth Sid
Darth Sid

Reputation: 69

For normalized floating point representation, the Mantissa (fractional bits) = 1 + f. This is sometimes called an implied leading 1 representation. This is a trick for getting an additional bit of precision for free since we can always adjust the exponent E so that significant M is in the range 1<=M < 2 ...

You are almost correct but must take into consideration the implied 1. If it is denormalized (meaning the exponent bits are all 0s) you do not add an implied 1.

I would solve this problem as such...

1  01110  001

bias = 2^(k-1) -1 =        14

Exponent = e - bias       

14 - 15 = -1
  1. Take the fractional bits ->> 001
  2. Add the implied 1 ->> 1.001
  3. Shift it by the exponent, which is -1. Becomes .1001
  4. Count up the values, 1(1/2) + 0(1/4) + 0(1/8) + 1(1/16) = 9/16
  5. With the a negative sign bit it becomes -9/16

hope that helps!

Upvotes: 2

user539810
user539810

Reputation:

You seem to have the correct concept, including an understanding of the excess-N representation, but you're missing a crucial point.

The 3 bits used to encode the fractional part of the magnitude are 001, but there is an implicit 1. preceding the fraction bits, so the full magnitude is actually 1.001, which can be represented as an improper fraction as 1+1/8 => 9/8.

2^(-1) is the same as 1/(2^1), or 1/2.

9/8 * 1/2 = 9/16. Take the sign bit into account, and you arrive at the answer -9/16.

Upvotes: 2

Related Questions