420 likes | 433 Views
19.3 Representation of Numeric Data. Fixed-point Representation. Numbers within computers can be expressed by. Sign-and-magnitude representation Two’s complement representation. Sign-and-magnitude Representation. The most significant bit represents the sign of the number:.
E N D
19.3 Representation of Numeric Data
Fixed-point Representation • Numbers within computers can be expressed by • Sign-and-magnitude representation • Two’s complement representation
Sign-and-magnitude Representation • The most significant bit represents the sign of the number: 1 for negative and 0 for positive • The remaining bits represent the magnitude of the number.
Bits for magnitude Sign bit
Binary fraction Sign bit 0 0 0 1 1 1 1 0 Binary Fraction in Sign-and-magnitude Representation = 11.112 = 21 + 20 + 21+ 22 = 2 + 1 + 0.5+ 0.25 = 3.7510
Binary fraction Sign bit 1 1 0 1 1 1 1 1 = 10111.112 = (24 + 22 + 21+ 20 + 21+ 22) = (16 + 4 + 2 + 1 + 0.5+ 0.25) = 23.7510
Two’s Complement Representation • The most significant bit represents a negative quantity. • The magnitude of the number is the sum of all digit values of the bits.
With the two’s complement representation, it is easy to change a positive number to the corresponding negative number and vice versa.
The steps are as follows: • Change all 0s to 1s. • Add 1 to the rightmost digit.
Binary fraction Most significant bit 0 0 1 0 1 1 1 0 Binary Fraction in Two’s Complement Representation = 101.1102 = 22 + 20 + 21+ 22 = 5.7510
Binary fraction Most significant bit 1 0 0 1 0 0 1 1 = 1001.00112 = 23 + 20 + 23+ 24 = 6.812510
61 00111101 61 +) –74 +) 10110110 –) 74 –13 11110011 –13 Addition and Subtraction in Two’s Complement Representation = 13(valid) • Subtraction can be done by complementation and addition.
61 +) 74 135 00111101 +) 01001010 10000111 = 121 (invalid) • The result is invalid because of an overflow error.
11000011 –61 +) 10110110 +) –74 1 01111001 –135 The extra bit is discarded because this is an 8-bit code. = 121 (invalid) • The result is invalid because of an overflow error.
11000011 –61 –61 +) 01001010 –) –74 +) 74 1 00001101 13 13 The extra bit is discarded because this is an 8-bit code. = 13(valid)
Comparisons between Sign-and-magnitude and Two’s Complement Representation
Floating-point Representation • A number is composed of a fraction part called a mantissa and a power called an exponent. • It represents numbers in a wider range.
Sign of mantissa Sign of exponent Exponent Mantissa 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 • Bit 0 to bit 7 represent the exponent and bit 8 to bit 15 represent the mantissa.
Normalisation • A standardised floating point representation. • The first bit of the mantissa must be non-zero.
0 1 1 1 0 1 0 0 0 0 0 0 0 0 1 1 Mantissa Exponent • For example, 7.2510 = 111.012 20 = 0.111012 23
Example 19.17 Express 1001.0112 in floating-point representation.
0 1 0 0 1 0 1 1 0 0 0 0 0 1 0 0 Solution 1001.0112 = 0.10010112 24 The floating-point representation is:
Example 19.18 Express 0.0000011112 in floating-point representation.
0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1 Solution 0.0000011112 = 0.11112 25 The floating-point representation is:
Example 19.19 Convert 1110000100000110, which is in floating-point representation, into a decimal value.
Solution 1110000100000110 = 0.11000012 26 = 0110000.12 = 48.510
Comparisons between Fixed-point and Floating-point Representation
Truncation Errors • It means dropping off any extra digits which cannot be accommodate.
Example 19.20 Truncate 123.88 to 4 significant figures.
123.8 Solution 123.88 This causes a truncation error. The error is 123.88 123.8 = 0.08
0.1010102 Example 19.21 Truncate 0.10101012 to 6 bits. Solution 0.10101012
Rounding Errors • It means shortening a number by deleting one or more digits in the least significant positions.
Increasing by one the remaining far right digit if the truncated digit is greater than or equal to half of the number base.
Example 19.22 Round 123.88 to 4 significant figures.
123.9 Solution 123.88 This causes a rounding error. The error is 123.9 123.88 = 0.02
0.1010112 Example 19.23 Round 0.10101012 to 6 bits. Solution 0.10101012
Overflow and Underflow Errors • Since the fixed-point and floating- point representations of a number have their own ranges, this causes • An overflow error if the number exceeds the range that can be represented.
An underflow error if the number is too small to be represented.