Information Representation Floating Point
Information Representation Floating Point
CSCI 230
Information Representation:
Floating Point Representation
Dale Roberts
Fractional Numbers
Examples: 456.7810 = 4 x 102 + 5 x 101 + 6 x 100 + 7 x 10-1+8 x 10-2
1011.112 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 1 x 2-1 + 1 x 2-2
= 8 + 0 + 2 + 1 + 1/2 + ¼
= 11 + 0.5 + 0.25 = 11.7510
2 1 0 -1 -2 -3
22 21 20 2-1 2-2 2-3
4 2 1 ½ ¼ 1/8
x x x x
Dale Roberts
Conversion from decimal number system to binary system
Examples: 7.7510 = (?)2
4 2
Examples: try 5.625B
1 1/2 1/4 1/8
=0.5 =0.25 =0.125
Dale Roberts
Fractional Numbers (cont.)
Exercise 1: Convert (0.625)10 to its binary form
Solution: 0.625 x 2 = 1.25 extract 1
0.25 x 2 = 0.5 extract 0
0.5 x 2 = 1.0 extract 1
0.0 stop
(0.625)10 = (0.101)2
Dale Roberts
Fractional Numbers (cont.)
Exercise 3: Convert (0.8125)10 to its binary form
(0.8125)10 = (0.1101)2
Dale Roberts
Fractional Numbers (cont.)
Errors
One source of error in the computations is due to back and
forth conversions between decimal and binary formats
Example: (0.6)10 + (0.6)10 = 1.210
Dale Roberts
Floating Point Number Representation
If x is a real number then its normal form representation is:
x = f • Base E
where f : mantissa
E: exponent
exponent
Example: 125.3210 = 0.12532 • 103
mantissa
- 125.3210 = - 0.12532 • 103
0.054610 = 0.546 • 10 –1
The mantissa is normalized, so the digit after the fractional point is non-zero.
Note that in binary, the leading digit is always 1, so it is normally hidden.
If needed the mantissa should be shifted appropriately to make the first digit
(after the fractional point) to be non-zero & the exponent is properly adjusted.
Dale Roberts
Normalizing Numbers
Example:
Dale Roberts
Floating Point Number Representation
Assume we use 16-bit binary pattern for normalized binary
form based on the following convention (MSB to LSB)
Sign of mantissa (±)= left most bit (where 0: +; 1: - )
Mantissa (f)= next 11 bits, leading 1 is assumed, m=1.f
Exponent (E) = next 4 bits, bias 7
20=7 (0111). 21=8 (1000), 2-1=6 (0110)
f = 1.?1?2?3?4…?11 ?12…?15
x = ± f • Base E
E : converted to binary, b1b2b3b4
MSB LSB
?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?10 ?11 b1 b2 b3 b4
+:0
- :1 Excess-7
Dale Roberts
Floating Point Number Representation
Question:
How the computer expresses the 16-bit
approximation of 1110.111010111111 in normalized
binary form using the following convention
Sign of mantissa = left most bit (where 0: +; 1: - )
Mantissa = next 11 bits, leading 1 is hidden, really represents 12 bits
Exponent = next four bits, bias 7
sign mantissa exponent
Step 1: Normalization
1110.111010111111 = + 1.110111010111111 * 2 +3
Dale Roberts
Floating Point Number Representation
Question:
Interpret the normalized binary number
0110 0000 0000 0100 B
Answer:
0 11000000000 0100 B = 1.11B *2(4-7)=-3 = 0.00111B
= 7/32 = 0.21875D
Dale Roberts
Real Life Example: IEEE 754
IEEE Standard 754 is the representation of
floating point used on most computers.
Single precision (float) is 32 bits or 4 bytes with
the following configuration.
1 sign bit 8 exponent 23 fraction
Dale Roberts
Real Life Example: IEEE 754
IEEE 754 Examples: Normalized Numbers
Dale Roberts
Real Life Example: IEEE 754
Double precision (double) is 64 bites or 8 bytes
with the following configuration.
Dale Roberts
IEEE 754 Converter
The Java Applet IEEE 754 Converter is an
interactive demonstration that let’s you enter a
floating point number and see its IEEE 754
implementation.
Dale Roberts
Appendix. IBM 370
The 32 Bit Single Precision Floating Point Format for IBM 370
Base = 16
Exponent = Excess-64 notation (i.e., compute binary equivalent, then subtract 64)
Sign = sign of number (0: positive, 1: negative)
Mantissa = normalized fraction (i.e. first digital after ‘.’ is non-zero)
Dale Roberts
Acknowledgements
These slides where originally prepared by Dr. Jeffrey Huang, updated by Dale
Roberts.
IEEE 754 information was obtained from Steve Hollasch
http://stevehollasch.com/cgindex/coding/ieeefloat.html.
IEEE 754 examples were obtained from Tony Cassandra at St. Edward’s
University.
IEEE 754 Converter. http://www.h-schmidt.net/FloatApplet/IEEE754.html.
Dale Roberts