binary real numbers. introduction computers must be able to represent real numbers (numbers w/...
TRANSCRIPT
![Page 1: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/1.jpg)
Binary Real Numbers
![Page 2: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/2.jpg)
Introduction
Computers must be able to represent real numbers (numbers w/ fractions)
Two different ways: Fixed-point Floating-point
NOTE: Everything in binary uses powers of two
![Page 3: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/3.jpg)
Decimal Review
Digits to the right of the decimal point correspond to negative powers of 10
102 101 100 . 10-1 10-2
100 10 1 . 0.1 0.01
![Page 4: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/4.jpg)
Binary Fractions
2-1 2-2 2-3 2-4 2-5 2-6
0.5 0.25 0.125 0.0625 0.03125 0.0015625
1/2 1/4 1/8 1/16 1/32 1/64
![Page 5: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/5.jpg)
Fixed Point Notation
1. Multiply each 1 by the corresponding power of 2
2. Add up the resulting powers of 2
Example:
11.012 = 2 + 1 + ¼ = 3.2510
00111.0102 = 4 + 2 + 1 + ¼ = 7.2510
![Page 6: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/6.jpg)
Floating-Point Notation
Floating-point notation is essentially the computer’s way of storing a number that has been normalized
3 different parts of any number: Mantissa: normalized number Exponent: power to which the base is raised Sign: of both mantissa and exponent
Decimal Example:12.5 = 0.125 x 102 normalized!
![Page 7: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/7.jpg)
Normalization Steps
1. Beginning with a fixed point number
2. Normalize the number such that the radix point (decimal point) is all the way to the left (produces the mantissa)
3. Multiply the resulting number by the base raised to an exponent
![Page 8: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/8.jpg)
Floating-Point ExampleWhat is 12.5 in floating-point representation?1. Convert 12.5 to binary fixed point
12.510 = 1100.12
2. Normalize the number by moving the radix point, producing the mantissa
1100.12 = 0.11001 * 24
3. Fill in the bits for each of the three parts of any real number:1. Sign (2 bits)2. Mantissa (# bits varies)3. Exponent (# bits varies)
4. NOTE: 2’s complement may be applied to the mantissa or the exponent if either are negative
![Page 9: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/9.jpg)
Placing the Bits
Assume you have the following: 1 bit for the mantissa sign 8 bits for the mantissa 1 bit for the exponent sign 6 bits for the exponent
SM M M M M M M M M S E E E E E E E
Example:
0.11001 * 24 0 00011001 0 000100
![Page 10: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/10.jpg)
Another Example
Convert -12.510 to binary:
1. Convert 12.5 to fixed point 01100.1
2. Normalize 0.11001 * 24
3. Convert exponent base to binary: 4 0100
4. 2s complement the mantissa by flipping bits and adding 1: 011001 100111
5. Final number 1 00111 0100
![Page 11: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/11.jpg)
Upper & Lower Bounds Assume you have the following:
1 bit for the mantissa sign 8 bits for the mantissa 1 bit for the exponent sign 6 bits for the exponent
What is the upper bound for the floating-point number?
What is the lower bound for the floating-point number?
What happens if we convert a floating-point number to an integer?
![Page 12: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/12.jpg)
Integers vs. Floating-point
integers: smaller range than floating-point all numbers within the range are 100% accurate
floating-point large range of numbers not all numbers within the range can be
represented accurately Example: 2.9999999999999 repeating
![Page 13: Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways: Fixed-point Floating-point](https://reader035.vdocuments.us/reader035/viewer/2022072011/56649e375503460f94b276f3/html5/thumbnails/13.jpg)
Possible Errors
truncation error round off errors using floating-point numbers
because not all real numbers can be represented accurately
overflow error attempting to represent a number that is greater
than the upper bound for the given number of bits underflow error
attempting to represent a number that is less than the lower bound for the given number of bits