n301/Numbering Systems
n301.tplt
Internal Representation - 2
real numbers- represented using scientific notation
- 24378 = 2.378 x 104
- components are sign, mantissa, and exponent
Why binary?
Electronic bistable environment
Reliability- with only 2 values, can be widely separated
- therefore clearly differentiated
- "drift" causes less error
Limitations
Fixed numbers of bits for a number- size depends on computer design
Limits on size of integers- e.g., -32768 to +32767 (16 bit word)
Limit on size of decimal numbers (exponent)
Limit on accuracy of decimal numbers (mantissa)
Floating point number representation
If x is any real number, its normal form representation is,
x = f * 10E
Ex: 125.32 = 0.12532 * 103
-125.32 = -0.12532 * 103
0.65 = 0.65 * 100
Floating point number representation 2
The number f of the representation is called the mantissa and the E is the exponent.
diagram
sign of mantissa | | sign of exponent | |
| d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 |
| digits of mantissa | | digits of exponent |
Example 1
Ex: Let x = 125.32. Then the representation is, x = 0.12532 * 103
Example 2
Ex: Let x = -0.0325475. Then the representation is, x = -0.3255 * 10-1
Binary representation of decimal numbers
Recall, the general binary representation of a positive integer is,
dn2n + dn - 12n - 1 + ... + d121 + d020
Example 3.1
Ex: Convert decimal 43 to binary.
43/2 = 21 + 1 5/2 = 2 + 1
21/2 = 10 + 1 2/2 = 1 + 0
10/2 = 5 + 0 1/2 = 0 + 1
Example 3.2
i.e. continue division by 2, noting all remainders, until a quotient of zero is reached. The resulting bit sequence, reads backwards,
101011 = 43. (32 + 8 + 2 + 1 = 43)
Binary representation of decimal numbers 2
the general binary representation of a positive number less than 1 is,
d-12-1 + d-22-2 + d-32-3...
Example 4.1
Ex: Convert .625 into binary.
.625 x 2 = 1.250 (extract the 1)
.250 x 2 = 0.500 (extract the 0)
.500 x 2 = 1.000 (extract the 1)
Example 4.2
The digits extracted are taken in the order extracted. In this case, the result is .101 (1/2 + 1/8 = 5/8 = .625)
Example 5.1
Ex: Convert 1/3 into binary.
Example 5.2
Ans: .010101010...
Binary representation of decimal numbers 3
One source of error in computations is due to back and forth conversion between decimal and binary.
Example 6.1
Ex: Find the sum of .6 + .6?
Example 6.2
1. Convert .6 to binary:
Ans: .1001100110011...
Example 6.3
2. Find sum:
Ans: .10011001
.10011001
1.00110010
Example 6.4
3. Convert answer back to decimal:
1 + 1/8 + 1/16 + 1/128 = 1.195 (actual sum = 1.2)
Example 6.5
Error = 1.2 - 1.195 = .005 due to roundoff made during conversions.
Example 7.1
Ex: Find a 16 bit representation of the approximation 1.414 to the square root of 2.
Example 7.2
a) Convert left side of the decimal point.
Ans: 1
Example 7.3
b) Convert right side of the decimal point. Using multiplicative method we get,
0.828 1.656 1.312 0.624 1.248 0.496
0.992 1.984 1.968 1.936 1.872 1.744
1.488 0.976 1.952
Example 7.4
c) required 16 bit approximation is,
1.0110 1001 1111 101
Example 7.5
d) convert this back to decimal and find the roundoff error.
Example 8.1
Ex: Express the 16 bit approximation
11.0010 0100 0011 11 to pi in normalized form.
Example 8.2
Ans: the normalized form is,
.1100 1001 0000 1111 x 22
In normalized form the leading 1 appears next to the decimal point.
Example 9.1
Ex: Interpret the string 0110 1110 0000 0100 using the following convention:- the leading bit (most significant bit, MSB) is the sign of mantissa (sm).
- next 11 bits corresponds to mantissa (m).
- next bit tells the sign of the exponent (se).
- next three bits corresponds to exponent (e).
Example 9.2
Ans: the parts are:
sm = 0; m = 11011100000; se = 0; e = 100
Shifting the decimal point four places to the right (?) gives,
1101.11, which is equal to 13.75