Chrome Obie
Chrome Obie

Reputation: 1

A negative floating number to binary

So the exercise says: "Consider binary encoding of real numbers on 16 bits. Fill the empty points of the binary encoding of the number -0.625 knowing that "1110" stands for the exposant and is minus one "-1"

                _ 1110_ _ _ _ _ _ _ _ _ _ _                              "

I can't find the answer and I know this is not a hard exercise (at least it doesn't look like a hard one).

Upvotes: 0

Views: 8293

Answers (3)

Rudy Velthuis
Rudy Velthuis

Reputation: 28806

Let's ignore the sign for now, and decompose the value 0.625 into (negative) powers of 2:

0.625(dec) = 5 * 0.125 = 5 * 1/8 = 0.101(bin) * 2^0

This should be normalized (value shifted left until there is a one before the decimal point, and exponent adjusted accordingly), so it becomes

0.625(dec) = 1.01(bin) * 2^-1 (or 1.25 * 0.5)

With hidden bit

Assuming you have a hidden bit scenario (meaning that, for normalized values, the top bit is always 1, so it is not stored), this becomes .01 filled up on the right with zero bits, so you get

sign = 1                        -- 1 bit
exponent = 1110                 -- 4 bits
significand = 0100 0000 000     -- 11 bits

So the bits are:

1 1110 01000000000

Grouped differently:

1111 0010 0000 0000(bin) or F200(hex)

Without hidden bit (i.e. top bit stored)

If there is no hidden bit scenario, it becomes

1 1110 10100000000

or

1111 0101 0000 0000(bin) = F500(hex)

Upvotes: 2

Jan Raufelder
Jan Raufelder

Reputation: 287

First of all you need to understand that each number "z" can be represented by

z = m * b^e

m = Mantissa, b = bias, e = exponent

So -0.625 could be represented as:

-0.625 * 10^ 0
-6,25 * 10^-1
-62,5 * 10^-2
-0,0625 * 10^ 1

With the IEEE conversion we aim for the normalized floating point number which means there is only one preceding number before the comma (-6,25 * 10^-1)

In binary the single number before the comma will always be a 1, so this number will not be stored.

You're converting into a 16 bit float so you have:

1 Bit sign 5 Bits Exponent 10 Bits mantissa == 16Bits

Since the exponent can be negative and positive (as you've seen above this depends only on the comma shifting) they came up with the so called bias. For 5 bits the bias value is 01 111 == 15(dez) with 14 beeing ^-1 and 16 beeing ^1 ...

Ok enough small talk lets convert your number as an example to show the process of conversion:

  1. Convert the pre-decimal position to binary as always
  2. Multiply the decimal place by 2 if the result is greater 1, subtract 1 and notate 1 if it's smaller 0 notate 0. Proceed this step until the result is == 0 or you've notated as many numbers as your mantissa has
  3. shift the comma to only one pre-decimal and count the shiftings. if you shifted to the left add the count to the bias if you have to shift to the right subtract the count from the bias. This is your exponent
  4. Dertmine your sign and add all parts together

-0.625
1. 0 to binary == 0

2.
0.625 * 2 = 1.25 ==> -1
0.25 * 2 = 0.5 ==> 0
0.5 * 2 = 1 ==> -1
Abort

3. The intermediary result therefore is -0.101
shift the comma 1 times to the right for a normalized floating point number:
-1.01
exponent = bias + (-1) == 15 - 1 == 14(dez) == 01110(bin)

4. put the parts together, sign = 1(negative), (and remember we do not store the leading 1 of number)

1 01110 01
since we aborted during our mantissa calculation fill the rest of the bits with 0:
1 01110 01 000 000 00

Upvotes: 0

Rishit Sanmukhani
Rishit Sanmukhani

Reputation: 2269

The IEEE 754 standard specifies a binary16 as having the following format:

Sign bit: 1 bit
Exponent width: 5 bits
Significand precision: 11 bits (10 explicitly stored)

Equation = exp(-1, signbit) x exp(2, exponent-15) x (1.significantbits)

Solution is as follows,

-0.625 = -1 x 0.5 x 1.25
significant bits = 25 = 11001
exponent = 14 = 01110
signbit = 1
ans = (1)(01110)(0000011001)

Upvotes: -1

Related Questions