Represent the following decimal number in IEEE standard floating-point format in a single precision method (32-bit) representation method. i. (65.175)10 ii. (-307.1875)10
Represent the following decimal number in IEEE standard floating-point format in a single precision method (32-bit) representation method. i. (65.175)10 ii. (-307.1875)10
IEEE 754 single precision uses 32 bits: 1 sign bit, 8 exponent bits (bias 127) and 23 fraction bits. A normalised number is written as $(-1)^s \times 1.f \times 2^{e}$. The stored exponent is $E = e + 127$. The leading 1 is not stored, because every normalised number starts with 1, so keeping it would waste a bit.
The bias 127 is added so that the exponent field is always a positive number. This lets two floating point numbers be compared like plain integers. The exponent patterns $00000000$ and $11111111$ are kept for zero, denormal numbers, infinity and NaN (not a number). So normal numbers use stored exponents from 1 to 254.
The method has three parts. First, convert the number to binary. Second, normalise it to the form $1.f \times 2^e$. Third, find $E = e + 127$ and write the sign, exponent and fraction in order.
(i) 65.175
The number is positive, so the sign bit is $0$. Convert the integer and fraction parts separately. The integer part is $65 = 1000001_2$. For the fraction, multiply by 2 again and again and note the integer parts:
$$0.175 = 0.001011,0011,0011\ldots_2$$
The first digits come from $0.175 \times 2 = 0.35$ (digit 0), $0.35 \times 2 = 0.7$ (digit 0), $0.7 \times 2 = 1.4$ (digit 1), then $0.4 \times 2 = 0.8$ (digit 0), and so on. The pattern $0011$ repeats forever, so the fraction never ends.
So the number is $1000001.001011001100\ldots_2$. Move the binary point 6 places left to normalise:
$$65.175 = 1.000001001011001100\ldots_2 \times 2^{6}$$
The stored exponent is:
$$E = 6 + 127 = 133 = 10000101_2$$
The fraction needs 23 bits. We take the digits after the leading 1 and round the last bit, because the next digits are $1001\ldots$, which is more than half. The fraction is $00000100101100110011010$. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 0 | 10000101 | 00000100101100110011010 |
In hexadecimal this is $\text{0x4282599A}$.
(ii) -307.1875
The number is negative, so the sign bit is $1$. The integer part is $307 = 100110011_2$. The fraction is exact:
$$0.1875 = 0.0011_2$$
So the number is $100110011.0011_2$. Move the point 8 places left:
$$307.1875 = 1.001100110011_2 \times 2^{8}$$
The stored exponent is:
$$E = 8 + 127 = 135 = 10000111_2$$
The fraction is $001100110011$ followed by 11 zeros to fill 23 bits. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 1 | 10000111 | 00110011001100000000000 |
In hexadecimal this is $\text{0xC3999800}$.
To check, decode the second answer: $-1.001100110011_2 \times 2^{8} = -1.1999\ldots \times 256 = -307.1875$. The first answer is the nearest 32-bit value to $65.175$, so it has a tiny rounding error of the order of $10^{-6}$. This is normal, because $0.175$ cannot be written exactly in binary.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextUsing Booth algorithm perform the multiplication on the following 6-bit unsigned integer 1