In: Computer Science
Assume that a floating-point number system has base 2, word length 32 bits, mantissa length 24 bits, and does rounding. Assume also that the first bit is implicit. Represent the numbers 1/2, 2/3 and 3/5 as floating-point numbers in this system. (Hint: For less confusion, you might want to write out all 25 binary digits.)
Could you please me give me full procedure?
A binary single precision representation of floating point number has 3 parts:
1) Sign bit - this is a single bit to represent the sign of the number (0 for positive and 1 for negative).
2) Exponent - This is the exponent part of the fraction (eg 1.011006) here 6 is the exponent part. It can be positive to represent numbers greater than 1, or negative to represent numbers less than 1. to represent this number in binary, we add 127 to it for the negative numbers in the floating point.
Eg, to represent 6 in the exponent we add 127 = 133. So, it becomes 10000101
Or to represent -5 in the exponent we add 127 = 122. so, it becomes 01111010
3) Mantissa - After we move the decimal point to the point where only one non-zero value is to its left (eg, 110.0110 becomes 1.100110), we discard the 1 left to the decimal point and the rest becomes the mantissa.
For this exercise, we have mantissa of length 24 and the sign bit is implicitly assumed, so we will just represent the Exponent (8 bits) and the mantissa(24 bits).
1) 1/2 in fractions is 0.5
Converting to binary:
0 in binary is 0. fractional part 0.5 in binary:
0.5*2 = 1.0 (integral part: 1, fractional part is 0) we stop here.
So, 0.5 in binary is 0.1
Exponent becomes -1 as the number is less than 1. And we add 127 for the representation: 126
in binary: 1111110
Mantissa is 1.
So, 01111110 10000000000000000000000 (not including sign bit)
2) 2/3 in fractions is 0.67
In binary for the fractional part:
0.67*2 = 1.34 (integral part: 1)
0.34*2 = 0.68 (integral part: 0)
0.68*2 = 1.36 (integral part:1)
0.36*2 = 0.72 (integral part: 0)
0.72*2 = 1.44 (integral part: 1)
0.44*2 = 0.88 (integral part: 0)
0.88*2 = 1.76 (integral part: 1)
0.76*2 = 1.52 (integral part: 1)
0.52*2 = 1.04 (integral part: 1)
0.04*2 = 0.08 (integral part: 0)
....
In binary it becomes: 0.1010101110
Here, the exponent is again -1, so adding 127 to it we get 126. In binary: 01111110.
Mantissa 1010101110
Floating representation: 01111110 101010111000000000000000
3) 3/5 in fraction is 0.6
In binary the fractional part:
0.6*2 = 1.2 (integral part: 1)
0.2*2 = 0.4 (integral part: 0)
0.4*2 = 0.8 (integral part: 0)
0.8*2 = 1.6 (integral part: 1)
0.6*2 = 1.2 (integral part: 1) repeating now
So, it becomes 0.100100100..
Exponent is -1, becomes 126.
Mantissa is 100100100...
Floating rep: 01111110 100100100100100100100100