Floating point number worksheet

CSCI206 Activity 24: Real Binary Numbers ​Name:________________________________
1. Convert the numbers 0.75, 0.9453125, and 0.2 to binary using 8 bits to the right of the
decimal point (truncate if necessary).
2. Convert the binary numbers 0.11110000, 0.10101010, and 0.01111111 to decimal.
The Institute of Electrical and Electronics Engineers (IEEE) defines the standard way to
represent floating point numbers in computing in standard 754 (IEEE 754) using a floating point
format. The general (normalized) representation is written mathematically as:
The data encoded in the ​N-​ bit binary value are:
● sign​ - a 1 bit value (always the first bit) 0 = positive, 1 = negative
● exp ​- an unsigned number representing the exponent, the value ​bias​ is a known
constant for an ​N​ bit floating point number. It is subtracted from the unsigned value to
yield a signed exponent.
● b​i​ ​- the fractional part of the number (​note the implicit plus 1​)
Format
Half Precision (16 bit)
Single Precision (32 bit)
Double Precision (64 bit)
Fractional Digits
10+1
23+1
52+1
Exponent Digits
5
8
11
Bias Value
15
127
1023
For example to represent 0.15625 we first have to write this value in binary.
This has to be normalized to account for the implicit +1.
The sign is positive (​0​), the fraction is ​0.0100...​2​, and the exponent is -3. The exponent must be
biased by adding 127, so we actually encode 124 (​01111100​2​).
1
On the next page, ​show the representation of 0.75, 0.9453125, and 0.2 using both ​half
precision ​and ​single precision​ IEEE754 format (16 and 32 bits).
Image ​http://en.wikipedia.org/wiki/File:Float_example.svg​ ​licensed under the ​Creative Commons
Attribution-Share Alike 3.0 ​(http://creativecommons.org/licenses/by-sa/3.0/deed.en)
1
3. Complete the table with the correct IEEE754 floating point values ​written as a hexadecimal
number​ using half-precision and single-precision (next page).
Decimal
Half (16-bits) (Hex)
Single (32 bits) (Hex)
0.75
0.9453125
0.2
0.75
S
EXP
FRACTION
15
14 13 12 11 10
9
8
7
6
5
4
3
2
1
0
6
5
4
3
2
1
0
6
5
4
3
2
1
0
0.9453125
S
EXP
1
5
1
4
FRACTION
1
3
1
2
1
1
1
0
9
8
7
0.2
S
EXP
FRACTION
15
14 13 12 11 10
9
8
7
0.75
S
EXP
3
1
3
0
2
9
2
8
2
7
2
6
2
5
2
4
2
3
1
9
1
8
1
7
1
6
1
5
1
4
1
3
2
9
2
8
2
7
2
6
2
5
2
4
2
3
1
9
1
8
1
7
1
6
1
5
1
4
1
3
FRACTION
2
2
2
1
2
0
1
2
1
1
1
0
9
8
7
6
5
4
3
2
1
0
1
2
1
1
1
0
9
8
7
6
5
4
3
2
1
0
0.9453125
S
EXP
3
1
3
0
FRACTION
2
2
2
1
2
0
0.2
S
EXP
31
30 29 28 27 26 25 24 23
FRACTION
22 21 20 19 18 17 16 15 14 13 12 11 10 9
8
7
6
5
4
3
2
1
0
4. Show how to convert the following half precision IEEE754 numbers to their decimal
equivalent.
0xcd08
0x563f
5. Show how to convert the following single precision IEEE754 numbers to their decimal
equivalent.
0xc1a10000
0x42c7eb85