Data Representation in Computer Systems
Data Representation in Computer Systems
Depends on Memory
Organization of a
Computer
Decimal Number Systems
• Contains ten digits from 0 to 9
• base 10 number system
• The successive place value or position, left
to the decimal point holds units, tens,
hundreds, thousands, and so on.
Octal Number Systems
• Contains Eight digits from 0 to 7
• base 8 number system
• Octal number – represented in only 3 bits.
• The position of a digit represents the 0
power of the base(8). Example: 80
• The position of the last digit represents the
x power of the base(8). Example: 8x,
where x represents the last position.
• Examples:
(273)8, (5644)8, (0.5365)8, (1123)8, (1223)8.
Hexadecimal Number Systems
• Contains ten digits from 0 to 9 and 6 letters from A to
F.
• The letters from A to F defines numbers from 10 to
15.
• base 16 number system.
• The position of a digit represents the 0 power of the
base(16). Example: 160
• The position of the last digit represents the x power of
the base(16). Example: 16x, where x represents the
last position.
• Examples: (FAC2)16, (564)16, (0ABD5)16, (1123)16, (11F3)16.
Number Systems
• Numbers
• Unsigned Numbers (+)
• has only magnitude - no sign.
• Signed Numbers(+/-)
• has both magnitude and sign
• Sign bit – 0 – positive number
• Sign bit – 1 – Negative number
• Representing Binary Numbers
• n bits – can be used to represent--- 2n distinct numbers (0 to 2n-1)
For example: If n=3 bits, 23 = 8 distinct numbers (0 to 7)can be represented
(0-000, 1-001, 2-010, 3-011, 4-100, 5-101, 6-110, 7-111)
Unsigned Number Representation of 4 Bits
• If no. of bits 4, Unsigned 0 to 2n-1
• then for unsigned numbers, these four bits can store the decimal values from
0 to 24-1 (decimal values 0 to 15).
No. of Unsigned numbers that can be stored in
bits (n) n bit representation
3 Decimal Numbers 0 to 7 0 to 23-1
4 D. Numbers 0 to 15 0 to 24-1
5 D. Numbers 0 to 32 0 to 25-1
6 D. Numbers 0 to 63 0 to 26-1
7 D. Numbers 0 to 127 0 to 27-1
8 D. Numbers 0 to 255 0 to 28-1
……. …… ……
Unsigned 0 to 2n-1
Signed (Sign Magnitude Representation)-2n-1+1 to 2n-1-1
Signed (One’s Complement Representation)-2n-1+1 to 2n-1-1
Signed (Two’s Complement Representation)-2n-1 to 2n-1-1
Sign Magnitude Representation of 4 Bits
T
w
One’s Complement Representation of Signed Numbers
• One’s Complement – One way of representing a negative number.
• One’s complement of a Positive value representation
– no change in both sign bit and
magnitude.
Sign-Magnitude Representation
1
=1100
• Here again the most significant bit will indicate the sign 0 for positive,
1 for negative.
(Two’s Complement) Signed -2n-1 to 2n-1-1
Advantages Expansion of Bit Length: Add additional bit positions to the left
• Unique representation of 0. and fill in with the value of the original sign bit.
• Subtraction can be done using addition. Overflow Rule: If two numbers with the same sign (both positive
• Leads to substantial saving in circuitry. or both negative) are added, then overflow occurs if and only if the
result has the opposite sign.
Features of Two’s complement
Features of Two’s complement
To conclude: Pros and cons of integer representation
• Signed magnitude representation:
• 2 representations for 0
• Simple
• 255 different numbers can be represented.
• Need to consider both sign and magnitude in arithmetic
• Different logic for addition and subtraction
• 1’s complement representation:
• 2 representations for 0
• Complexity in performing addition and subtraction
• 255 different numbers can be represented.
• 2’s complement representation:
• Only one representation for 0
• 256 different numbers can be represented.
• Arithmetic works easily
To Conclude: Signed Binary Numbers
-9 +9
Signed magnitude representation 1 1001 0 1001
Signed 1’s complement representation 1 0110 0 1001
Signed 2’s complement representation 1 0111 0 1001
-0 +0
Signed magnitude representation 1 0000 0 0000
Signed 1’s complement representation 1 1111 0 0000
Signed 2’s complement representation -None- 0 0000
To Conclude: Range of Binary Numbers
0+4+1= 5
• 5 is the unsigned decimal value of the binary number 0101
Binary to Decimal Conversion (Unsigned)
Sign bit
– Hence multiply by –(27)
Signed Binary Number Arithmetic
• Add or Subtract two signed binary number including its sign bit
111 Carry
010 Values
1
+101
1
1000
Fixed Point Binary Numbers - Subtraction
• Borrow rules
• 0-0 = 1-1 = 0 borrow 0
• 1-0 = 1 borrow 0
• 0-1 = 1 borrow 1
• The rules of the decimal base applies to binary as well.
• To be able to calculate 0-1, we have to “borrow one” from the next
digit.
left 12
0202
1010
-011
1
0011
Fixed Point Binary Numbers - Addition
& Subtraction
Fixed Point Binary Numbers - Addition
& Subtraction
Overflow and Underflow
• Overflow Overflow
• Overflow occurs - When the addition of • Assume 4-bit restriction and 2’s complement
two binary numbers represented • Maximum possible value: 24-1 – 1 = 7
in ‘n’ bits - yields a result that is 610 + 310 = should be 910
greater than the maximum possible
value that can be represented with ‘n’ But, signed 9 can’t be represented with 4 bits…
bits. Hence it produces a wrong result.
• Possible with both integers and floating 01102 610
point numbers. +00112 +310
• Example: adding 1 to the maximum 10012 -710 not good!
value of a uint 8 (255) would cause
an overflow, resulting in a value of
0.
Overflow and Underflow
• Underflow Underflow
• Underflow occurs - When an
arithmetic operation of two binary • Assume 4-bit restriction and 2’s complement
numbers represented in ‘n’ • Minimum possible value: -(24-1) = -8
bits - yields a result that is lesser -510 + -510 = should be -1010
than the minimum possible value
that can be represented with ‘n’ But, signed -10 can’t be represented with 4 bits…
Hence it produces a wrong result.
bits.
• Underflow is a bit trickier to 10112 -510
understand because it has to do +10112 +-510
with precision in floating 01102 not good!
610
points.
Overflow of Signed Numbers
carry
carry and
generated, overflo
but no w
overflow The answer must be -9 (which
needs 5 bits and cannot be
represented with 4 bits). Hence
the answer calculated shows +7
(Because of overflow)
no carry
and no
no carry and
overflow
overflow
Overflow
• Overflow and Underflow – Errors
• To check for Overflow error - need a simple error-detection method that doesn't
require any additional arithmetic.
• the most elegant solution is to check for the sign of the sum and compare it against the signs
of the numbers added.
• Obviously, two positive numbers added together should give a positive result, and two negative numbers
added together should give a negative result.
• Notice that whenever we had a condition of overflow in the example problems, the sign of the result was
always opposite of the two added numbers: +1710 plus +1910 giving -2810, or -1710 plus -1910 giving +2810.
• By checking the signs alone we are able to tell that something is wrong.
• But what about cases where a positive number is added to a negative number? What sign should
the sum be in order to be correct. Or, more precisely, what sign of sum would necessarily indicate an
overflow error?
• There will never be an overflow error when two numbers of opposite signs are added together!
• The reason for this is apparent when the nature of overflow is considered. Overflow occurs when the magnitude
of a number exceeds the range allowed by the size of the bit field. The sum of two identically-signed numbers
may very well exceed the range of the bit field of those two numbers, and so in this case overflow is a possibility.
However, if a positive number is added to a negative number, the sum will always be closer to zero than either of
the two added numbers: its magnitude must be less than the magnitude of either original number, and so
overflow is impossible.
Fixed Point Arithmetic
Operations-
Multiplication
Fixed Point Binary Numbers -
Multiplication
• Multiplication
• Generation of Partial Products.
• Each successive partial product is shifted one position to the left relative to
the preceding partial product
• Final product = sum of the Partial Products.
27 26 25 24 23 22 21 20
Multiplicand is shifted
by displacing it through
an array of adders.
Multiplication of Signed numbers
Signed number representation
• For an n bit representation: MSB- sign bit(0 or 1), n-1(magnitude)
0 0 0 0 0 1 1 0 1 nsion is
Sign
exte in red
shown
0 0 0 0 0 0 0 0
0 0 0 1 1 0 1
0 0 0 0 0 0
- 029 0
28
1
27
0
26
0
25
0
24
1
23
1
22
1
21
1 - 143
= (0*-209)+ (0*28)+ (1*27)+(0*26)+(0*25)+(0*24)+(1*23)+(1*22)+(1*21)+(1*20)
2
=128+8+4+2+1 =143 answer
Multiplication of Signed numbers
• Case 2: Multiply the given numbers (-13) x (+11) (Positive
Multiplier)
1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 0 1 1
Sign extension is
0 0 0 0 0 0 0 0 shown in red
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 0 1 1 1 0 0 0 1 - 143
- 29 28 27 26 25 24 23 22 21
= (1*-29)+ (1*28)+ (0*27)+(1*26)+(1*25)+(1*24)+(0*23)+(0*22)+(0*21)+(1*20)
20
=-512+256+64+32+16+1
=-143 answer
Multiplication of Signed numbers
• Case 3: Multiply the given numbers (+13) x (-11) (Negative Multiplier)
• number of bits required to represent the number +13 is 5 bits
• number of bits required to represent the number -11 is 5 bits
• Convert decimal to binary
• 13 1101 111011
• Take 2’s complement of 110100+1=0101
• +13 01101(5 bits=0(sign), 1101(magnitude))
• -1110101(5 bits=1(sign), 0101(magnitude))
• Since the multiplier is negative(-), take 2’s complement of both M(+13) and Q(-
11) and proceed as -13 and 11
• Take 2’s complement of (+13)10010+1=10011(-13)
• Take 2’s complement of (-11)01010+1=01011(11)
• -13 10011(5 bits=1(sign), 0011(magnitude))
• +1101011(5 bits=0(sign), 1011(magnitude))
Multiplication of Signed numbers
Since the multiplier is negative(-), take 2’s complement
of both M(+13) and Q(-11) and proceed as -13 and
11 1 0 0 1 1 - 13
0 1 0 1 1 ( + 11 )
1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 0 1 1
Sign extension is
0 0 0 0 0 0 0 0 shown in red
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 0 1 1 1 0 0 0 1 - 143
- 29 28 27 26 25 24 23 22 21
= (1*-29)+ (1*28)+ (0*27)+(1*26)+(1*25)+(1*24)+(0*23)+(0*22)+(0*21)+(1*20)
20
=-512+256+64+32+16+1
=-143 answer
Multiplication of Signed numbers
• Case 4: Multiply the given numbers (-13) x (-11)
• number of bits required to represent the number -13 is 5 bits
• number of bits required to represent the number -11 is 5 bits
• Convert decimal to binary
• 13 1101 111011
• Take 2’s complement of 130010+1=0011
• Take 2’s complement of 110100+1=0101
• -13 10011(5 bits=1(sign), 0011(magnitude))
• -1110101(5 bits=1(sign), 0101(magnitude))
• Since the multiplier is negative(-), take 2’s complement of both M(-13) and Q(-11)
and
proceed as 13 and 11
• Take 2’s complement of (-13)01100+1=01101(+13)
• Take 2’s complement of (-11)01010+1=01011(+11)
• +13 01101(5 bits=0(sign), 1101(magnitude))
• +1101011(5 bits=0(sign), 1011(magnitude))
Multiplication of Signed numbers
0 1 1 0 1 + 13
0 1 0 1 1 ( + 11 )
0 0 0 0 0 0 1 1 0 1
0 0 0 0 0 1 1 0 1 nsion is
Sign
exte in red
shown
0 0 0 0 0 0 0 0
0 0 0 1 1 0 1
0 0 0 0 0 0
- 029 0
28
1
27
0
26
0
25
0
24
1
23
1
22
1
21
1 - 143
= (0*-209)+ (0*28)+ (1*27)+(0*26)+(0*25)+(0*24)+(1*23)+(1*22)+(1*21)+(1*20)
2
=128+8+4+2+1 =143 answer
Multiplication of Signed numbers
1111010 0 0 0×M
000110 0 1 +1 × M
0000 (Sign bit of the result) 1 0 -1 × M
0
1 1 0× M
1 0 0 0 0 1 1 0 0 answer is 12
(Ignore -27 26 25 24 23 22 21 20 =(0*-27)+ (0*26)+(0*25)+(0*24)+(1*23)+(1*22)+(0*21)+(0*20)=8+4=12
carry)
Case 2: 6 X - Multiplication of Signed numbers - Booth Algorithm
S
2 tep 1: Find binary representation of Multiplicand (6) and multiplier
(-2) Including sign bit. 6 0110 and -2 1110
Step 2: Recoding multiplier 11100 0 0 -1 0
Step 3: Multiplication operation Multiplier Booth
0110X Bit i Bit (i-1) Multiplier
0 0 -1 0 (Bit to (Bit to the Bit
-1 take 2’complement
modify) right ofi)
00000000 of multiplicand
1111010 0 0 0×M
000000 0 1 +1 × M
0000 (Sign bit of the result) 1 0 -1 × M
0
1 1 0× M
11110100 answer is -
12 =(1*-2 )+ (1*2 )+(1*2 )+(1*2 )+(0*2 )+(1*2 )+(0*2 )+(0*2 )=-128+64+32+16+4=-12
7 6 5 4 3 2 1 0
Case 3: -6 X Multiplication of Signed numbers - Booth Algorithm
2 tep 1: Find binary representation of Multiplicand (-6) and multiplier
S
(2) Including sign bit. -6 1010 and 2 0010
Step 2: Recoding multiplier 00100 0 +1 -1 0
Step 3: Multiplication operation Multiplier Booth
1010X Bit i Bit (i-1) Multiplier
0+1-1 0 (Bit to (Bit to the Bit
-1 take 2’complement
modify) right ofi)
00000000 of multiplicand
0000110 0 0 0×M
111010 0 1 +1 × M
0000 (Sign bit of the result) 1 0 -1 × M
0
1 1 0× M
11110100 answer is -
12 =(1*-2 )+ (1*2 )+(1*2 )+(1*2 )+(0*2 )+(1*2 )+(0*2 )+(0*2 )=-128+64+32+16+4=-12
7 6 5 4 3 2 1 0
Case 4: -6 X - Multiplication of Signed numbers - Booth Algorithm
S
2 tep 1: Find binary representation of Multiplicand (-6) and multiplier
(-2) Including sign bit. -6 1010 and -2 1110
Step 2: Recoding multiplier 11100 0 0 -1 0
Step 3: Multiplication operation Multiplier Booth
1010X Bit i Bit (i-1) Multiplier
0 0 -1 0 (Bit to (Bit to the Bit
-1 take 2’complement
modify) right ofi)
00000000 of multiplicand
0000110 0 0 0×M
000000 0 1 +1 × M
0000 (Sign bit of the result) 1 0 -1 × M
0
1 1 0× M
00001100 answer is
12 =(0*-2 )+ (0*2 )+(0*2 )+(0*2 )+(1*2 )+(1*2 )+(0*2 )+(0*2 )=8+4=12
7 6 5 4 3 2 1 0
Multiplication of Signed numbers
– Booth Algorithm
• Hardware for Booth’s Multiplication
Multiplication of Signed numbers
– Booth Algorithm
Flow Chart
M - Multiplicand
Q - Multiplier
Q0 - least significant bit of QR
Q-1 - previous least significant bit of QR
A-0
Count - number of bits in multiplier
Example: Multiplication of Signed numbers - Booth Algorithm
Multiply 7 x
3 Multiplicand =7 Binary equivalent is 0111M
Multiplier = 3 Binary equivalent is 0011Q
-7 Binary equivalent is 1001 -M
A0 0 0 0 A 1 1 10
-M 1 0 0 1 M 0 1 1 1
A1 0 0 1 A 0 1 0 1
Step A Q Q1
- Action Count
1 0 0 0 0 0 0 1 1 0 Initial 4
2 1 0 0 1 0 0 1 1 0 AA-M
1 1 0 0 1 0 0 1 1 Right Shift 3
3 1 1 1 0 0 1 0 0 1 Right Shift 2
4 0 1 0 1 0 1 0 0 1 AA+M
0 0 1 0 1 0 1 0 0 Right Shift 1
1 0 0 0 0 1 1 0 1 0 Initial 4
A0 0 0 0
2 1 0 0 1 1 1 0 1 0 AA-M -M 1 0 0 1
11 0 0 1 1 1 0 1 Shift 3 A1 0 0 1
3 00 1 1 1 AA+M A1 1 0 0
1 1 1 0
+M 0 1 1 1
00 0 1 1 1 1 1 0 Shift 2
Discard 1
4 1 0 1 0 1 1 1 1 0 AA+M A 10 0 1 1
1 1 0 1 0 1 1 1 1 Shift 1 0 0 1
A0
Shift 0 -M 1 0 0 1
5 1 1 1 0 1 0 1 1 1
-27 26 25 24 A1 0 1 0
23 22 21 20 Convert binary to decimal and the
answer is -21
Example: Multiplication of Signed numbers - Booth Algorithm
Multiply -7 x
3 Multiplicand =-7 Binary equivalent is 1001M
Multiplier = 3 Binary equivalent is 0011Q
Step A Q Q1
- Action Count
1 0 0 0 0 0 0 1 1 0 Initial 4
A0 0 0 0
2 0 1 1 1 0 0 1 1 0 AA-M -M 0 1 1 1
0 0 1 1 1 0 0 1 1 Shift 3 A0 1 1 1
3 0 0 0 1 1 1 0 0 1 Shift 2 A0 0 0 1
+M 1 0 0 1
4 1 0 1 0 1 1 0 0 1 AA+M A1 0 1 0
1 1 0 1 0 1 1 0 0 Shift 1
5 1 1 1 0 1 0 1 1 0 Shift 0
Step A Q Q1
- Action Count
1 0 0 0 0 1 1 0 1 0 Initial 4
A0 0 0 0
2 0 1 1 1 1 1 0 1 0 AA-M -M 0 1 1 1
00 1 1 1 1 1 0 1 Shift 3 A0 1 1 1
3 11 0 0 1 1 1 0 1 AA+M A0 0 1 1
+M 0 0 1
11 1 0 0 1 1 1 0 Shift 2
1
4 0 1 0 1 0 1 1 1 0 AA-M A1 1 0 0
A1 1 1 0
0 0 1 0 1 0 1 1 1 Shift 1
-M 0 1 1 1
5 Shift 0 A0 1 0 1 Discard 1
0 0 0 1 0 1 0 1 1
-27 26 25 24 23 22 21 20 Convert binary to decimal and the
answer is 21
Multiplication of Signed numbers
– Booth Algorithm
Practice Problems
•Show the step by step multiplication process using Booth
algorithm when the following binary numbers are
multiplied. Assume 5-bit registers that hold signed
numbers. The multiplicand in both cases is +15.
•(+15) × (+13)
•(+15) × (-13)
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
• Fast Multiplication / Modified Booth Algorithm
• Bit-pair recoding halves the maximum number of summands (versions of the
multiplicand)
• - Reduces the number of Partial Products
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
Multiplier Multiplier bit Booth
Note: on the right Multiplier Bit
Bit i+1 Bit (i)
(left bit) (Bit to modify) i-1
If multiplier bit is
Sign extension
0 0 1 +1 × M
0 +2 -2Bit Pair Recoding Multiplier
0 1 0 +1 × M
0 1 1 0 1
0 +
2
- 2
0 1 1 +2 × M
1 1 1 1 1 0 0 1 1 0
0 0 0 1 1 0 1 0 1 0 0 -2 × M
0 0 0 0 0 0
1 0 0 0 1 0 0 1 1 1 0 1 0 1 -1 × M
64+8+4+2=78 1 1 0 -1 × M
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 2: 13 x -6
0 1 1 0 1 ( + 13 ) Multiplier Multiplier Booth
1 1 0 1 0 -6 bit on the Multiplier
Bit i+1 Bit (i)
• Bit- Pair Recoded Multiplier (left bit) (Bit to
right Bit
modify) i-1
Implied 0
1 1 1 0 1 0 0
0 0 0 0×M
Sign extension 0 -1 -2 Bit Pair Recoding Multiplier
0 0 1 +1 × M
0 1 1 0 1
0 - - 2 0 1 0 +1 × M
1
1
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1 0
0 1 1 +2 × M
0
1
0
1
0
1
0
0
0
1
0
1 0 0 1 0
-78 1 0 0 -2 × M
- 29 28 27 26 25 24 23 22 21 1 0 1 -1 × M
= (1*-29)+ 0(1*28)+ (1*27)+(0*26)+(1*25)+(1*24)+(0*23)+(0*22)+(1*21)+(0*20)
2
=-512+256+128+32+16+2 1 1 0 -1 × M
=-78 answer
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 3: -13 x 6
1 0 0 1 1 (- Multiplier Multiplier Booth
13 ) bit on the Multiplier
0 0 1 1 0 +6 Bit i+1 Bit (i)
• Bit- Pair Recoded Multiplier (left bit) (Bit to
right Bit
modify) i-1
Implied 0
0 0 0 1 1 0 0
0 0 0 0×M
Sign extension 0 +2 -2Bit Pair Recoding Multiplier
1 0 0 1 1 0 0 1 +1 × M
0 1 0 +1 × M
0 +2 - 2
0 0 0 0 0 1 1 0 1 0
1 1 1 0 0 1 1 0 0 1 1 +2 × M
0 0 0 0 0 0
1 1 1 0 1 1 0 0 1 0
-78 1 0 0 -2 × M
- 29 28 27 26 25 24 23 22 21
1 0 1 -1 × M
=-512+256+128+32+16+2
20 =-78 answer 1 1 0 -1 × M
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 4: -13 x -6
1 0 0 1 1 ( - 13 ) Multiplier Multiplier Booth
1 1 0 1 0 -6 bit on the Multiplier
Bit i+1 Bit (i)
• Bit- Pair Recoded Multiplier (left bit) (Bit to
right Bit
modify) i-1
Implied 0
1 1 1 0 1 0 0
0 0 0 0×M
Sign extension 0 -1 -2 Bit Pair Recoding Multiplier
0 0 1 +1 × M
1 0 0 1 1
0 -1 - 2 0 1 0 +1 × M
0 0 0 0 0 1 1 0 1 0 0 1 1 +2 × M
0 0 0 0 1 1 0 1
1 0 0 -2 × M
0 0 0 0 0 0
64+8+4+2=78 1 0 1 -1 × M
0 0 0 1 0 0 1 1 1 0
- 29 28 1 1 0 -1 × M
27 26 25 24 23 22 21 20
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
Practice Problems
•Show the step by step multiplication process using Bit-pair
recoding technique when the following binary numbers are
multiplied. Assume 5-bit registers that hold signed
numbers. The multiplicand in both cases is +15.
•(+15) × (+13)
•(+15) × (-13)
Fixed Point Arithmetic
Operations- Division
Division
• First, the bits of the dividend are examined from left to right, until the
set of bits examined represents a number greater than or equal to
the divisor
• this is referred to as the divisor being able to divide the number
• Until this event occurs, 0s are placed in the quotient from left to right
• When the event occurs, a 1 is placed in the quotient and the divisor is
subtracted from the partial dividend
• The result is referred to as a partial remainder
Binary Division - Example
Circuit
Arrangement
Hardware Implementation of binary division
An n-bit positive divisor is loaded into register
M
• If the sign of A is 1,
• Shift A and Q left one binary
position
n cycles (Subtract M from A and place the result back in A)
• A-M A
set q0 to 0 and
A+M A (restore A);
Otherwise,
set q0 to 1 , No ADD (No Restore);
• Repeat these steps n times
Restoring Division – Example
Dividend = 8 Divisor = 3
1 •
•
Shift A and Q left one binary position
A-M A
in A)
(Subtract M from A and place the result back
• If the sign of A is 1,
set q0 to 0 and
A+M A (restore A);
Otherwise,
set q0 to 1 , No ADD (No Restore);
• Repeat these steps n times
Restoring Division – Example 2
• Q (Dividend) = 7 and M (Divisor)= 3
Non - Restoring Division
• Avoids restoring step in every cycle – improves the performance
• Drawbacks of Restoring Division
• In restoring,
if A is +ve (0),
left shift, A-M ----- 2A-
M if A is –ve (1),
A+M, Left Shift, A-M
------------- 2(A+M)-M
=2A+M
Non - Restoring Division - Steps
If the sign of A is 1,
Shift A and Q left one binary position (Left Shift),
A+M A;
Otherwise,
n cycles Shift A and Q left one binary position (Left Shift),
A-M A;
If the sign of A is 1,
set q0 to 0
Otherwise,
set q0 to 1,
Repeat these steps n times
After n cycles,
If the sign of
A is 1,
A+M A; (Restore)
Non - Restoring Division – Example
Dividend = 8 Divisor = 3
1
If the sign of A is 1,
Shift A and Q left one binary position (Left Shift),
A+M A;
Otherwise,
n cycles Shift A and Q left one binary position (Left Shift),
A-M A;
If the sign of A is 1,
set q0 to 0
Otherwise,
set q0 to 1,
Repeat these steps n times
After n cycles,
If the sign of A is 1,
A+M A; (Restore)
Restoring Division – Examples
Case 1: Dividend = 12 Divisor = 3
Restoring Division – Examples
Case 1: Dividend = 12 Divisor = 3
Restoring Division – Examples
Case 2: Dividend = -7 Divisor = 3
• Dividend = -ve
• Divisor = +ve
• Algorithm:
Restoring Division – Examples
Case 3: Dividend = 7 Divisor = -3
Case 4: Dividend = -7 Divisor = -3
Restoring Division – Examples
• Perform Division using Restoring and Non - Restoring Algorithm.
Dividend = 11 Divisor = 2
Excess 8 format
Floating Point Representation – Examples
negative
20 127 + 20 = 147
negative
...
stored [23 0.4 x 2
– 6 + 127 = bits]
1 0 0 1 1 0 1 1 0 1 1 0.8
1 1 0133
0 100 0 1 0 1 0 0 1 1 0 0 ...1 1 0 1 1 0 0 1 1 0 0 1 0.8 1 0x 20 1 1 0
sig biased significan 1.6
n exponent d 0.6 x 2
1.2
Floating Point Representation - Example
•Represent 85.125 in Floating Point Single Precision Format
•Steps: 3. Identify Sign bit
1. Binary Conversion sign = 0
85 = 1010101, 0.125 = 001
85.125 = 1010101.001 4. Find the Exponent with Bias Value
Biased exponent for Single precision :
2. Normalize the Mantissa Excess 127+6=133
1.010101001 x Exponent = 133 = 10000101
26
Normalized Mantisa = 010101001 E-127=6
E=133
(add 0's to complete the 23 bits) Exponent =
133 =
0 is:10000101
The IEEE 754 Single precision 01010100100000000000000
100001
Floating Point Representation - Example
•Represent 85.125 in Floating Point Double Precision Format
•Steps: 3. Identify Sign bit
1. Binary Conversion sign = 0
85 = 1010101, 0.125 = 001
85.125 = 1010101.001 4. Find the Exponent with Bias Value
Biased exponent for Double precision :
2. Normalize the Mantissa Excess 1023+6 =1029
1.010101001 x Exponent = 1029 = 10000000101
26
Normalized Mantisa = 010101001 E-1023=6
E=1029
(add 0's to complete the 52 bits) Exponent =
0 The IEEE 754 Double
10000000101 precision is: 1029 =
0101010010000000000000000000000000000000000000000000
1000000
Floating Point Representation - Example
•Represent 1259.125 in Floating Point Single Precision Format
•Step1: Convert to Binary Step 2: Normalize the Mantissa
Floating Point Representation - Example
•Represent 1259.125 in Floating Point Single Precision Format
•SP format (Excess-127) DP format (Excess-1023)
Conversion of Floating Point Binary
Representation to Decimal- Example
Convert 0110100000000011 to FP Decimal. (Assume M=9 bits, E=6 bits) in the form S.M.E
(Assume Exponent is not Biased and Mantissa is not normalized)
Conversion of Floating Point Binary
Representation to Decimal- Example
Convert 0110100000000011 to FP Decimal. (Assume M=9 bits, E=6 bits) in the form S.M.E
(Assume Exponent is not Biased and Mantissa is not normalized)
Steps:
1. Convert E to decimal.
2. Place the radix point in Mantissa based on
the decimal Exponent (E).
(If 23 – place radix point after first 3 bits.
Neglect the sign bit)
3. Follow Binary to Decimal Procedure.
Conversion of Floating Point Binary
Representation to Decimal- Example
Convert 0101010000000010 to FP Decimal. (Assume M=9 bits, E=6 bits) in the form S.M.E
(Assume Exponent is not Biased and Mantissa is not normalized)
Floating Point Representation
• Overflow generally means
that values have grown too
large to be represented.
• Underflow is a less serious
problem because is just
denotes a loss of precision,
which is guaranteed to be
closely approximated by
zero.
Exercise Problems
Express the number - (640.5)10 in IEEE 32 bit and 64 bit floating point format
Solution:
• IEEE 32 BIT FLOATING POINT FORMAT
MSB 23 bits
sign Biased Mantissa/Significand
8 bits Exponent (Normalized)
Step 1: Express the given number in
binary form (640.5) =
1010000000.1* 20
Step 2: Normalize the number into the form
1.bbbbbbb 1010000000.1* 20 = 1.
0100000001* 29
Exercise Problems
Express the number - (640.5)10 in IEEE 32 bit and 64 bit floating point format
Solution:
• IEEE 32 BIT FLOATING POINT FORMAT
MSB 23 bits
sign Biased Mantissa/Significand
8 bits Exponent (Normalized)
Step 3: For the 11 bit biased exponent field, the bias used is
2k-1-1 = 28-1-1 = 127
Add the bias 127 to the exponent 9 and convert it into binary in order to store for
8-bit biased
exponent. 127 + 9 =136 ( 1000 1000)
7
2
x
X = 1.01101 x 1.01101 x 27
27 – 0.110101 x
Y = 1.10101 x 27
• Normal2Multiplication
6 0.100101 x 27
• Normal Division
X = 3.7510 = 11.112 = 1.111 0.110011
x=21 95.625 1.111
Y 10
= 101
1.011111101
1111.101 2 = 1.011111101 x
26
Floating Point Arithmetic Operations
– Addition/Subtraction
0.0234 Not normalized
• Steps 0.234×10-1 -- Normalized
• Check for 0’s in the given decimal and normalize it. (If the MSB bit is Non-zero –> Normalized)
• Choose the number with smaller Exponent.
• Align Mantissas (Shift its Mantissa right to number of positions – difference
between exponents)
• Set the exponent of result = larger exponent
• Add or Subtract Mantissas and determine the sign
• Normalize the result, if necessary
For addition and subtraction, it is necessary
to ensure that both operand exponents have the same value
This may involves shifting the radix point of one of the operand to achieve
alignment
Floating Point Arithmetic Operations
Some problems that may arise during arithmetic operations are:
• Exponent overflow: A positive exponent exceeds the maximum
possible
exponent value and this may leads to + or - in some systems
• Exponent underflow: A negative exponent is less than the minimum possible
exponent value (eg. 2-200), the number is too small to be represented and
maybe reported as 0
• Significand underflow: In the process of aligning significands, the smaller number
may have a significand which is too small to be represented
• Significand overflow: The addition of two significands of the same sign may
result in a carry out from the most significant bit
Floating Point Arithmetic Operations
– Addition/Subtraction - Algorithm
Algorithm:
Floating Point Arithmetic Operations
– Addition - Example Normalize
No 2’s Complement
Direct Addition
= 273.125
Floating Point Arithmetic Operations
– Addition - Example
Floating Point Arithmetic Operations
– Subtraction - Example Normalize
No 2’s Complement
Direct Subtraction
...
only 24 bits can be stored
1 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0
1
32-bit register more than
+ half of the
1 LSB
...
0.4
stored [23
+ 3 + 127 = 1 1 0 0 0bits]
0 1 1 0 0 1
0 1 0130 ... 0 0 1 1 0 0 1 1 0 0 1 1
0 100 0 0 1 0 1 0 0 0 0 1 1 0 0 1 1
sig biased significan
n exponent d
Floating Point Arithmetic Operations
– Addition – in IEEE format
Align the smaller number with the larger number
68.310 + 12.2 10
shifting
by it to the right [increasing the exponent]
1000 0010 1.1000011001100110011 1000 0.0011000011001100110
0101 011
exponent mantissa exponent mantissa
ADD the mantissa
1.00010001001100110011010
+ 0.00110000110011001100110011
1.01000010000000000000000011
less than
half of the
0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0LSB0 0 0 0 0 0 0 0 0 0 0 0
sig biased significan
Store the result in IEEE single-precision
n exponent d
format
Flowchart- Addition/Subtraction
Z=X+Y and Z=X-Y
1.0110 x 27 1.0110 x 27
X = 1.01101 x 1 1
X–Y=
27 + x 27 – 0.11010 x 27
ZSUBTRACT Y = 1.10101 x 0.110101 1
Change sign of 26 10.00111 x 27 0.10010 x 27
Y
1 1
X = 1.01101
X+Y 0.100101 x
Y = 0.110101x x
=Z n n ye 27 Results ye
s2
Expoenent 7 Add
AD X= o Y= o s Round result
s signed normalize
D 0? 0?
Equal? significan d?
ds
ye ye n n
s s o o
n
o
1.0001111 x
28
RETURN Shift RETURN Significan n Decreme
significa d o nt 1.00101 x 26
nd right overflow exponen
? t
10.001111 x 1.00101 x
Significan
27yes Shift n 26
Exponen
Y = 0.110101 x d
= 0?
significa
nd right
o t
underflo
2no7 w?
ye
s
1.0001111 8
Put other Increme
number
in Z
x2 nt
expone
Report
underflow
RETURN nt
Z= X × Y
Floating Point Arithmetic Operations
– Multiplication - Example
Floating Point Arithmetic Operations
– Division - Algorithm
Z= X / Y
Floating Point Arithmetic Operations
– Division - Example
Practice Questions
• Perform FP Addition, Subtraction, Multiplication and Division fore the
following inputs
• 123 and 25
• 154 and 10
Representation of Non Numeric Data
(Character Codes)
Non-Numeric Data Representation
•Non-Numeric data use specific form of characters to represent.
•To save the text into bit sequence and decipher the bit sequence
into text, there must be a standard character set-bit mapping
table.
•Different Representation
• ASCII - American Standard Code for Information Interchange
• Unicode
• EBCDIC character code - Extended Binary Coded Decimal Interchange
Code
Non-Numeric Data Representation
There are several different variants of EBCDIC. Most of these differ in the
EBCDIC character code in hexadecimal indices
EBCDIC control character representation
Practice Problems
• Represent the following numbers in a) Sign and Magnitude b) 1s
complement and c) 2’s complement representation
i) +24 ii) - 24 iii) -8 iv) +13 v) -37
• 2. Multiply the following numbers using Booth algorithm.
i) 11* 13
ii) 11* -13
iii) -11* - 13
• 3. Show the step by step multiplication process using AC , QR and Q-1
registers for the below number
i) -15* 5
Practice Problems
• 4. Multiply the following numbers using modified booth algorithm / Bit pair recoding( Try
one problem using the registers(A, Q , Q-1 ) method)
i) 23 * 10
ii) 14 * -2
iii) -12* 8
• 5. Divide the following numbers using restoring division algorithm
i) 14/7
ii) 28/11
• 6. Divide the following numbers using non- restoring division algorithm
i) 18/9
ii) 27/4
• 7. Represent the following number in IEEE- 754 format
i) 12312.13
ii) -14.5