Represent the following decimal number in IEEE standard floating-point format in a single precision method (32 bit) representation method. (i) (85.125)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) (85.125)10 (ii) (-307.1875)10
IEEE 754 single precision uses 32 bits: 1 sign bit, 8 exponent bits with bias 127, and 23 fraction bits. A number is stored as $(-1)^s \times 1.f \times 2^{e}$, with the stored exponent $E = e + 127$. The leading 1 is implied, so it is not stored.
The method has three parts. First, convert the number to binary. Second, normalise it to the form $1.f \times 2^e$ by moving the binary point. Third, add the bias to $e$ and write the sign, exponent and fraction in order. The bias of 127 makes the stored exponent a positive number even for small values.
(i) 85.125
The number is positive, so $s = 0$. The integer part is $85 = 1010101_2$, and the fraction is exact, since $0.125 = 0.001_2$. So:
$$85.125 = 1010101.001_2 = 1.010101001_2 \times 2^{6}$$
The stored exponent is:
$$E = 6 + 127 = 133 = 10000101_2$$
The fraction $010101001$ is padded with zeros to 23 bits. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 0 | 10000101 | 01010100100000000000000 |
In hexadecimal this is $\text{0x42AA4000}$.
(ii) -307.1875
The number is negative, so $s = 1$. The integer part is $307 = 100110011_2$ and $0.1875 = 0.0011_2$. So:
$$307.1875 = 100110011.0011_2 = 1.001100110011_2 \times 2^{8}$$
The stored exponent is:
$$E = 8 + 127 = 135 = 10000111_2$$
The fraction $001100110011$ is padded with zeros to 23 bits. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 1 | 10000111 | 00110011001100000000000 |
In hexadecimal this is $\text{0xC3999800}$.
Both numbers have short binary fractions, so both are stored exactly with no rounding error.
To check the first answer, decode it: $E = 133$ gives $e = 6$. The value is $1.010101001_2 \times 2^6 = 1010101.001_2 = 85 + 0.125 = 85.125$. The second answer decodes in the same way to $-(256 + 32 + 16 + 2 + 1) - 0.1875 = -307.1875$, which matches.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextExplain the different cycles of an instruction execution.