Date post: | 28-Dec-2015 |
Category: |
Documents |
Upload: | jocelyn-shields |
View: | 223 times |
Download: | 1 times |
How could we represent fractions?
• In decimal:– As fractions : 1/5 – As decimals : 0.2
hundreds102
tens101
ones100
tenths10-1
hundredths
10-2
0 2 0
Column Pattern
• Negative powers of two:
2-3 = = = 0.125
23
822
421
220
12-1
0.52-2
0.252-3
0.1252-4
0.0625
Number
• Binary decimal:
10.112 = 2 + 0.5 + 0.25 = 2.7510
23
822
421
220
12-1
0.52-2
0.252-3
0.1252-4
0.0625
1 0 1 1
Number
• Binary decimal:
0.10012 = 0.5 + 0.0625 = 0.562510
23
822
421
220
12-1
0.52-2
0.252-3
0.1252-4
0.0625
0 1 0 0 1
Number
• Binary decimal:
0.10102 = 0.5 + 0.125 = 0.62510
23
822
421
220
12-1
0.52-2
0.252-3
0.1252-4
0.0625
0 1 0 1 0
• An attempt with 11 decimal digits:
• Can only approximate
More Digits
Binary Decimal Place 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 2-9 2-10 2-11
Bit 1 0 0 1 1 0 0 1 1 0 1
Value 0.5 0 0 0.0625 0.03125 0 0 0.003906 0.001953 0 0.000488
Total 0.600098
More Digits
• Given limited digits, must allocate them– To left of decimal:
Bigger values
– To right of decimal:More accurate values
25
3224
1623
822
421
220
12-1
0.52-2
0.25
21
220
12-1
0.52-2
0.252-3
0.1252-4
0.06252-5
0.031252-6
0.015625
Fixed Decimal Problems
• Fixed decimal points waste space:
400,000,000,000,000,000 0.000000000000025
Fixed Decimal Problems
• Fixed decimal points waste space:
400,000,000,000,000,000 vs 4.0 x 1017
0.000000000000025 vs 2.5 x 10-14
• In computers, space is precious– Computers use a floating decimal point
(Like scientific notation)
Floating Point
• Bits used to represent 3 parts:– Sign – Exponent – Fraction (or Mantissa)
Sign Exponent Mantissa
0 1 0 0 1 0 0 0
Exponent
• Binary integer in excess notation– Gives power of 2 to multiply by
100 = 0So 20
Sign Exponent Mantissa
0 1 0 0 1 0 0 0
Binary Value000 -4001 -3010 -2011 -1100 0101 1110 2111 3
Mantissa
• Fractional Value– Always a decimal
1000 = 0.5
Sign Exponent Mantissa
0 1 0 0 1 0 0 0
2-1
0.52-2
0.252-3
0.1252-4
0.0625
1 0 0 0
Examples
+ 20 x 0.5 = + 1 x 0.5 = + 0.5
Sign Exponent Mantissa
0 1 0 0 1 0 0 0+ 0 so 20 0.5
2-1
0.52-2
0.252-3
0.1252-4
0.0625
1 0 0 0
Examples
- 23 x 0.5625 = - 8 x 0.5625 = -4.5
Sign Exponent Mantissa
1 1 1 1 1 0 0 1- 3 so 23 0.5625
2-1
0.52-2
0.252-3
0.1252-4
0.0625
1 0 0 1
Examples
+ 2-4 x 0.25 = + 0.0625 x 0.25 = +0.015625
Sign Exponent Mantissa
0 0 0 0 0 1 0 0+ -4 so 2-4 or 0.25
2-1
0.52-2
0.252-3
0.1252-4
0.0625
0 1 0 0
Floating Point Math is HARD
• XOR the signs• Calculate new exponent– Excess Notation – different math rules!
• Calculate new mantissa– Normal binary multiplication
Sign Exponent Mantissa
0 1 0 0 1 0 0 0
Choices, choices
• Choices– More bits to exponent– More bits to mantissa– How we represent each• What is our excess start point?• Do mantissas have to start with 1?
32 Bit Floating Point
• PC processors are 32 or 64 bit– Size of data they can work on at one time
• IEEE specifies conventions for floating points: