Professional Documents
Culture Documents
Itec1000 Lecture Note 4
Itec1000 Lecture Note 4
Introduction
· 9’s complement is the decimal counter part of the binary 1’s complement
· Figure 4.5 in page 103 illustrates 3-digit number representation in 9’s complement
· Positive range matches the sign-and-magnitude representation positive range
· Negative range is different than the sign-and-magnitude representation negative range
· The sign of a number is determined by checking the most significant digit
o Positive when most significant digit values 0-4
o Negative when most significant digit values 5-9
Convert from sign-and-magnitude to 9’s complement
· Must specify the number of 9’s complement storage digits available to represent the number
· If number is positive no conversion is necessary (i.e. same as sign-and-magnitude representation)
o Pad the number with 0’s, if needed, to represent all the assigned number of storage digits
· If number is negative conversion is required (complement the number)
o Complementary base – number
· The complementary base is the highest value in the number supported by the given number of
digits
· Complementary base for:
o 3 digits = 999
o 5 digits = 99999
Examples
1. Represent –467 in 3-digit 9’s complement
o The number is negative so complement the number = 999 – 467
= 532
2. Represent –467 in 4-digit 9’s complement
o The number is negative so complement the number = 9999 – 467
= 9532
3. Represent 467 in 3-digit 9’s complement
o The number is positive so the 9’s complement is the same as the number
= 467
4. Represent 667 in 4-digit 9’s complement
o The number is positive so the 9’s complement is the same as the number
o Need to pad with zero to fill the entire storage space
= 0667
5. Represent 667 in 3-digit 9’s complement
o The number cannot be represented with only 3-digits (overflow occur)
o Maximum positive number the can be represent is 499
Convert from 9’s complement to sign-and-magnitude
· Determine whether the number is positive or negative (inspect the most significant digit)
· If the number is positive, the sign-and-magnitude equivalent is the same as the 9’s complement
· If the number is negative, complement the number
o Complementary base – number
o Add the negative sign
Examples
1. Convert 9990 to sign-and-magnitude representation
o The number is negative (most significant digit is 9)
o Complement the number: 9999 – 9990 = 9
o Add negative sign
= -9
2. Convert 595 to sign-and-magnitude representation
o The number is negative (most significant digit is 5)
o Complement the number: 999 – 595 = 404
o Add negative sign
= -404
3. Convert 4990 to sign-and-magnitude representation
o The number is positive (most significant digit is 4)
o The result is the same as the 9’s complement
= 4990
Addition and Subtraction Arithmetic
· Addition in 9’s complement is done using the following method:
o Add the 2 numbers in the normal way
o Add 1 to the result if there is end-round carry
· An end-round carry occur if the result overflow the storage space
· Subtraction in 9’s complement is done using the following method:
o Complement any number with negative sign (i.e. eliminate the negative sign)
o Add the two numbers using the same method as the “Addition in 9’s Complement”
Examples
· Add (799 + 100)
o 799 + 100
= 899
· Add (799 + 300)
o 799 + 300 =(1)099
o Add end-round carry = 1 + 099
= 100
· Add (0799 + 0300)
o 0799 + 0300
= 1099
· Subtract (799 – 100)
o Find 9’s complement of 100 = 999 – 100 = 899
o Add 799 + 899 = (1) 698
o Add the end-round carry = 1 + 698
= 699
· Subtract (106 – 090)
o Find 9’s complement of 90 = 999 – 90 = 909
o Add 106 + 909 = (1)015
o Add end-round carry = 1 + 015
= 016
· Subtract (0106 – 0090)
o Find 9’s complement of 90 = 9999 – 90 = 9909
o Add 0106 + 9909 = (1) 0015
o Add end-round carry = 1 + 0015
= 0016
· Subtract (-40 - 2)
o Find 9’s complement of 40 = 99 – 40 = 59
o Find 9’s complement of 2 = 99 – 2 = 97
o Add 59 + 97 = (1) 56
o Add end-round carry = 1 + 56
= 57
· Typically, an overflow occur when the result of calculation does not fit into the storage space
· In 2’s complement an addition or subtraction overflow occur when the result overflows into the
sign bit
· An overflow can be detected when the sign of the result is an opposite of the sign of both numbers
· In computers, an overflow flag is used to test for an overflow (flag is set/reset at every
calculation)
· In 2’s complement an addition or subtraction carry occur when the result exceeds the storage
space
· A carry flag is used to test for carry (flag is set/reset at every calculation)
· Overflow and carry can occur independent of each other
· 4 possible outcomes as a result of addition or subtraction
o No overflow and No carry
o No overflow and carry
o Overflow and no carry
o Overflow and carry
· Overflow produces an incorrect result
· Carry still produces a correct result
Examples (addition of two 4-bit 2’s complement numbers)
o 0100 + 0010 = 0110 (4+2 = 6) no overflow and no carry (result is correct)
o 0100 + 0110 = 1010 (4+6 = -6) overflow and no carry (result is
incorrect)
o 1100 + 1110 = (1) 1010 (-4-2 = -6) no overflow and carry (result is correct)
o 1100 + 1010 = (1) 0110 (-4-6 = 6) overflow and carry (result is incorrect)