Search code examples
cbinaryfloating-point-conversion

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?


Solution

  • 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.