COMP228: System Hardware
Tutorial of Ch02: Data Representation
Numbers System
Example 1
Example 2
Example 3
Example 4
Example 5
Example 6
Example 7
Example 8
Taxonomy of integers numbers
Example 9
Example 10
Example 11
Example 12
Example 13
Example 14
Problems with Sign/Magnitude
1010 1001
0101 +5 0110+6
-2
-0
-1
1000 0111
-7
+0
-6
1111 1110
0000 0001
+1
+2
-5
-4 1100 Inner numbers: 0011 +3
1101
-3 1011 Binary
0010
representation 0100 +4
• Two different representations for 0! • Two discontinuities
+7
Seven Positive Numbers and “Positive” Zero
Seven Negative Numbers and “Negative” Zero
Example 15
Example 16
Example 17
S/M problems solved with 2s complement
Re-order Negative numbers to eliminate one Discontinuity
Note:
Negative Numbers still have 1 for the most significant bit (MSB)
-1
1111
0001
+0
-2
-3 1110
1101 -4 1100 -5 1011
-6 1010 1001
-7
-8
• Only one discontinuity now • Only one zero
• One extra negative number
+1
0000
1000
+4 0101 +5
0110 0111 +6
+7
+2 0011 +3
0010
0100
Eight Positive Numbers
Inner numbers: Binary representation
Example 18
Example 19
Example 20
Overflow Rule
Example 21
Example 22
Example 23
Valid Ranges
• For any integer data representation, there is a LIMIT to the size of number that can be stored.
• The limit depends upon number of bits available for data storage.
Unsigned Integer Ranges Range = 0 to (2n – 1)
where n is the number of bits used to store the unsigned integer.
Numbers with values GREATER than (2n – 1) would require more bits. If you try to store too large a value without using more bits, OVERFLOW will occur.
Unsigned Integer Ranges
Example: On a system that stores unsigned integers in 16-bit words:
Range = 0 to (216 –1) = 0 to 65535
Therefore, you cannot store numbers larger than 65535 in 16 bits.
Signed S/M Integer Ranges
Range = -(2(n-1) – 1) to +(2(n-1) – 1)
where n is the number of bits used to store the sign/magnitude integer.
Numbers with values GREATER than +(2(n-1) – 1) and values LESS than -(2(n-1) – 1) would require more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will occur.
S/M Integer Ranges
Example: On a system that stores unsigned
integers in 16-bit words:
Range = -(215 – 1) to +(215 – 1) = -32767 to +32767
Therefore, you cannot store numbers larger than 32767 or smaller than -32767 in 16 bits.
Floating Point
Example 24
Example 25
Example 26
0.1100 1000 * 0.1001 1010 = 0.0111 1000 0101 * 2^2 0.1111 0000 101 * 2^1
Example 27
IEEE-754 Floating-Point
• Floating point numbers can be stored into 32- bits, by dividing the bits into three parts:
the sign, the exponent, and the mantissa.
12910 32
IEEE-754 Floating-Point
• The first (leftmost) field of our floating point representation will STILL be the sign bit:
—0 for a positive number, —1 for a negative number.
Storing the Binary Form
How do we store a radix point?
– All we have are zeros and ones…
Make sure that the radix point is ALWAYS in the same position within the number.
Use the IEEE 32-bit standard
→ the leftmost digit must be a 1
Solution is Normalization
Every binary number, except the one corresponding to the number zero, can be normalized by choosing the exponent so that the radix point falls to the right of the leftmost 1 bit.
37.2510 = 100101.012 = 1.0010101 x 25 7.62510 = 111.1012 = 1.11101 x 22 0.312510 = 0.01012 = 1.01 x 2-2
IEEE-754 Floating-Point
• The second field of the floating point number will be the exponent.
• The exponent is stored as an unsigned 8-bit number, RELATIVE to a bias of 127.
—Exponent 5 is stored as (127 + 5) or 132 –132 = 10000100
—Exponent -5 is stored as (127 + (-5)) or 122 –122 = 01111010
Example 28
How would the following exponents be stored (8-bits, 127-biased):
2-10 28
Answers
2-10
exponent bias +127
28
-10 8-bit value
117 → 01110101
exponent 8 8-bit bias +127 value
135 → 10000111
Example 29
• The mantissa is the set of 0’s and 1’s to the right of the radix point of the normalized (when the digit to the left of the radix point is 1) binary number.
Ex: 1.00101 X 23
(The mantissa is 00101)
▪ The mantissa is stored in a 23 bit field, so we add zeros to the right side and store:
00101000000000000000000
Example 30
Ex 1: Find the IEEE FP representation of 40.15625
Step 1.
Compute the binary equivalent of the whole part and the fractional part. (i.e. convert 40 and .15625 to their binary equivalents)
Example 30
40 – 32 8 – 8
Result:
101000
.15625
-.12500
.03125
-.03125
Result:
.00101
0 .0
So: 40.1562510 = 101000.001012
Decimal Floating Point to IEEE standard Conversion
Step 2. Normalize the number by moving the decimal point to the right of the leftmost one.
101000.00101 = 1.0100000101 x 25
Decimal Floating Point to IEEE standard Conversion
Step 3. Convert the exponent to a biased exponent
127 + 5 = 132
And convert biased exponent to 8-bit unsigned
binary:
13210 = 100001002
Decimal Floating Point to IEEE standard Conversion
Step 4. Store the results from steps 1-3: Sign Exponent Mantissa
(fromstep3) (fromstep2)
0 10000100 01000001010000000000000
Decimal Floating Point to IEEE standard Conversion
Ex 2: Find the IEEE FP representation of –24.75 Step 1. Compute the binary equivalent of the whole
part and the fractional part.
24 .75
– 16 Result: – .50 Result:
8 11000 .25 .11 – 8 – .25
0 .0
So: -24.7510 = -11000.112
Decimal Floating Point to IEEE standard Conversion
Step 2.
Normalize the number by moving the decimal
point to the right of the leftmost one. -11000.11 = -1.100011 x 24
Decimal Floating Point to IEEE standard Conversion.
Step 3. Convert the exponent to a biased exponent
127 + 4 = 131
==> 13110 = 100000112
Step 4. Store the results from steps 1-3
Sign Exponent mantissa
1 10000011 1000110..0
IEEE standard to Decimal Floating Point Conversion.
• Do the steps in reverse order
• In reversing the normalization step move the radix point the number of digits equal to the exponent:
—If exponent is positive, move to the right —If exponent is negative, move to the left
Example 31
Convert the following 32-bit binary number to its decimal floating point equivalent:
Sign Exponent Mantissa
1 01111101 010..0
Example 31
Step 1: Extract the biased exponent and unbias it
Biased exponent = 011111012 = 12510 Unbiased Exponent: 125 – 127 = -2
Example 31
Step 2: Write Normalized number in the form:
Exponent
1 . ____________ x 2 Mantissa
For our number:
-1.01 x2–2
—-
Example 31
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part):
-0.01012 (negative exponent – move left) Step 4: Convert binary number to the FP equivalent
(i.e. Add all column values with 1s in them)
-0.01012 = – ( 0.25 + 0.0625) = -0.312510
Example 32
Convert the following 32 bit binary number to its decimal floating point equivalent:
Sign Exponent Mantissa
0 10000011 10011000..0
Example 32
Step 1: Extract the biased exponent and unbias it
Biased exponent = 10000112 = 13110 Unbiased Exponent: 131 – 127 = 4
Example 32
Step 2: Write Normalized number in the form:
1 . ____________ x 2 Mantissa
For our number:
1.10011 x 2 4
Exponent
—-
Example 32
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part:
11001.12 (positive exponent – move right) Step 4: Convert binary number to the FP equivalent
(i.e. Add all column values with 1s in them)
11001.1 = 16 + 8 + 1 +.5
= 25.510
Binary-Coded Decimal (BCD)
Example 33
Example 33
Error Detection
Example 33
Error Detection
Example 34
Example 35
Hamming Code
Hamming Code
Hamming Code
Hamming Code
Hamming Code