Title: Representation of Signed Numbers 1
1Representation of Signed Numbers 1
- Following three schemes are used.
- 1a) Signed Magnitude Scheme with different
characters as the sign. - 1b) Signed Magnitude Scheme with
- the numeric digits as the sign.
- 2) The Complement Schemes namely
- Assuming rbase / radix of the number system.
- 2a) (r-1)s Complement scheme.
- 2b) r s Complement Scheme.
-
2The Signed Magnitude scheme for representing
Numbers - 1
- The following scheme is used
- Positive Numbers
- / ltNo symbolgt ltMagnitudegt
- e.g. 123 (Decimal) , 3456 (Octal)
- A2B3 (Hex.), 110011 (Binary)
- 2) Negative Numbers
- - ltMagnitude gt e.g. 456 (Decimal)
- -A34F (Hex.) , -110011 (Binary)
3The pros cons of the illustrated Signed
Magnitude scheme
- Handling sign characters followed by numeric
magnitude i.e. alphanumeric processing is needed. - Two representations of ZERO (0) in any base
- 0 (0) -0
- Sign characters dont participate in any
Processing activity. - Operational Complexities involving sign
characters - e.g. 128 (Decimal) - 45 (Decimal)
- implies 128 PLUS 45.
4The Modified Signed Magnitude scheme
- Using digits to represent Sign.
- Conventions
- 1) Leading / Leftmost / Most Significant Digit
0 implies ve sign. - e.g. 0124 (Decimal) gt 124 , 01101 (Binary)
gt 1101 - 0A2BD (Hex) gt A2BD, 0345 (Octal) gt 345
- 2) Leading / Leftmost / Most Significant Digit
(r-1) , r being the base/radix implies - ve
sign. - e.g. 9124 (Decimal) gt -124 , 11101 (Binary)
gt -1101 - FA2BD (Hex) gt -A2BD, 7345 (Octal) gt -345
5The pros cons of the illustrated Signed
Magnitude scheme
- Two representations of ZERO (0) in any base
e.g. 00 gt 0 in any base/radix - while 90 gt -0 (Decimal), 10 gt -0 (Binary)
- F0 gt -0 (Hex) , 70 gt -0 (Octal)
- Sign digits dont participate in any Processing
activity. - Operational Complexities involving sign
characters - e.g. 0128 (Decimal) 945 (Decimal)
- implies 0128 PLUS 045.
6The (r-1)s Complement Scheme - 1
- 9s Complement in Decimal ( Base r 10)
- 1s Complement in Binary ( Base r 2)
- 7s Complement in Octal ( Base r 8)
- Es / 15s Complement in Hex (Base r 16)
- Rule 1
- (1) For ve numbers represent the sign by
- leading / leftmost 0.
7The (r-1)s Complement Scheme - 2
- Rule 2 For -ve numbers
- (1) Represent the ve number first (including
sign) by employing leading / leftmost 0. - (2) Subtract each digit of this ve number
representation (including the sign digit) - from (r-1) i.e. the Largest Digit of the
corresponding base / radix r.
8The (r-1)s Complement Scheme - 3
- Examples
- a) 123 in Decimal .
- Applying Rule 1 123 0123
- Using Rule 2 -123 (9999 0123) 9876
leading 9 gt -ve - b) 1101 in Binary .
- Applying Rule 1 1101 01101
- Using Rule 2 -1101 (11111 01101) 10010
leading 1 gt -ve - c) 12A6 in Hex .
- Applying Rule 1 12A6 012A6
- Using Rule 2 -12A6 (FFFFF 012A6) FED59
leading F gt -ve
9The (r-1)s Complement Scheme - 4
- Two representation of 0
- e.g. 00 gt 0 in any base.
- 90 gt -0 in Decimal , 10 gt -0 in Binary,
- F0 gt -0 in Hex, 70 gt -0 in Octal .
- Range of Values that can be represented using
n digits (including the sign digit) in base / - radix r
- -r n r(n-1) . r (n-1) 1
10The (r-1)s Complement Scheme 5(The Range of
Values )
- Assuming n (no. of digits) 3 in any base
including sign digit - (a) Decimal System
- Maximum value 10 (3-1) 1 10 2 1 gt100 1
gt 099 - Minimum value 10 3 - 10 (3-1) 103 102 gt1000
100 gt 900 gt -99 - (b) Binary System
- Maximum value 2 (3-1) 1 2 2 1 gt 3
(Decimal) gt 011 - Minimum value 2 3 - 2 (3-1) 23 22 gt 8 4
gt 4(Decimal) gt 100
11The (r-1)s Complement Scheme 6(The Arithmetic
Operations )
- 1) ADDITION C A PLUS B
- Case 1 Both the Operands A B are of same
sign - Step 1 Make A B equal size in terms of no. of
digits (including sign digit) by padding left
side of the smaller operand ( A OR B) with Sign
Extension i.e. by replicating the sign digit to
the left. - Step 2 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Check the MSDigit
/ Sign Digit. If it is invalid flash overflow
else accept result. - Case B. Carry is produced (End around carry). Add
carry digit with the generated result. Ignore any
subsequent carry. Check the MSDigit / Sign Digit.
If it is invalid flash overflow else accept
result.
12The (r-1)s Complement Scheme 7 ADDITION
Operation (Contd.)
- Case 2 Operands A B differs in sign
- Rule 1 Make A B equal size in terms of no. of
digits (including sign digit) by padding left
side with Sign Extension i.e. by copying the
sign. - Rule 2 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Accept result No
chance of Overflow . - Case B. Carry is produced (End around carry). Add
carry digit with the generated result. Ignore any
subsequent carry. Accept result No chance of
Overflow .
13The (r-1)s Complement Scheme 8 ADDITION
Operation (examples)
- Assumed n3 i.e. 3 digit decimal number
(including sign) - Decimal Ex. 1. Both Operands happen to be
ve - A 0 28, B 0 6 , B 0 06 (after sign
extension) - A 0 28
- B 0 06
- ---------------
- C 0 34 gt No End around Carry
valid sign ACCEPTED. - Ex. 2. Both Operands happen to be -ve
- A 9 28 , B 9 6 i.e. B 9 96 after
sign extension - A 9 28 - 71
- B 9 96 - 03
- -------------
- C 1 9 24 gt 9 24 PLUS (End Around Carry
1) 9 25 Accepted. -
- Check 9 25 - 74 (Valid Result)
14The (r-1)s Complement Scheme 9 ADDITION
Operation (examples)
- Decimal (contd.)
- Ex. 3. Both Operands happen to be ve
- A 0 28 B 0 76
- A 0 28
- B 0 76
- ---------------
- C 1 04 gt No End around Carry
invalid sign OVERFLOW. - Ex. 4. Both Operands happen to be -ve
- A 9 28 , B 9 06
- A 9 28 - 71
- B 9 06 - 93
- -------------
- C 1 8 34 gt 8 34 PLUS (End Around Carry 1)
8 35 invalid sign , overflow
15The (r-1)s Complement Scheme 10 ADDITION
Operation (examples)
- Decimal (Contd.)
- Ex. 5. One Operand (A) is ve while the other
(B) is ve - A 0 28 , B 9 76
- A 0 28 28
- B 9 76 -23
- --------------------
- C 1 0 04 PLUS End around Carry 1 0 05 .
Accepted - Ex. 6. One Operand (A) is -ve while the other
(B) is ve - A 9 28 , B 0 06
- A 9 28 - 71
- B 0 06 06
- ------------------------
- C 9 34 No End Around Carry . ACCEPTED
- - 65 Valid Result
16The (r-1)s Complement Scheme 11 ADDITION
Operation (examples)
- Binary (Assume n 4 bits including SIGN bit)
-
- Ex.1. Both Operands ve
- A 0 101 B 011 gt B 0 011 (After sign
extension) - Rule 1 A 0 101 5 (Decimal)
- B 0 011 3 (Decimal)
- ---------------
- C 1 000 -8 (Decimal) gt No
End around Carry . But Result sign (1) differs
from the two Operands sign (0) hence Overflow. - Ex.2. Both Operands -ve
- A 1 110 , B 1 01 i.e. B 1 101 After
sign extension - A 1 110 - 1 (Decimal)
- B 1 101 - 2 (Decimal)
- -------------
- C 1 1 011 PLUS (End Around Carry 1) 1100.
Result sign does not change Accepted. - 1100 - 3 (Decimal) valid
17The (r-1)s Complement Scheme 12 ADDITION
Operation (examples)
- Binary (Contd.)
- Ex. 3 . Operand A is ve but Operand B is ve
- A 0 101 B 101 gt B 1 101 (after sign
extension) - A 0 101
- B 1 101
- ---------------
- C 10 010 PLUS End around Carry 1 0 011
ACCEPTED. - Ex. 4. Operand A is ve while Operand B is ve
- A 1 101 , B 0 110
- A 1 101
- B 0 110
- -------------
- C 1 0 011 PLUS End Around Carry 1 0 100.
ACCEPTED. -
18The (r-1)s Complement Scheme 13 SUBTRACTION
Operation
- 1) SUBTRACTION C A MINUS B
- Case 1 Both the Operands A B are of same
sign - Step 1 Obtain (r-1)s complement of B.
- Step 2 Make A B equal size in terms of no.
of digits (including sign digit) by padding left
side of the smaller sized operand (A OR B) with
Sign Extension i.e. by replicating the sign digit
to the left. - Step 3 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Accept result No
chance of overflow. - Case B. Carry is produced (End around carry). Add
carry digit with the generated result. Ignore any
subsequent carry. Accept result No chance of
overflow.
19The (r-1)s Complement Scheme 14 SUBTRACTION
Operation
- Case 2 Operands A B differs in sign
- Step 1 Obtain (r-1)s complement of B.
- Step 2 Make A B equal size in terms of no.
of digits (including sign digit) by padding left
side of the smaller sized operand (A OR B) with
Sign Extension i.e. by replicating the sign digit
to the left. - Step 3 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Check the MSDigit
/ Sign Digit. If it is invalid flash overflow
else accept result. - Case B. Carry is produced (End around carry). Add
carry digit with the generated result. Ignore any
subsequent carry. Check the MSDigit / Sign Digit.
If it is invalid flash overflow else accept
result.
20The (r-1)s Complement Scheme 15 SUBTRACTION
Operation Examples
- Decimal Assuming n3 (including sign digit)
- Ex. 1 Both Operands happen to be ve
- A 0 28 B 0 6 gt 9 3 (9s Complement gt
9 93 after sign extension - A 0 28
- B 9 93
- ---------------
- C 1 0 21 PLUS (End around Carry 1)
0 22 . ACCEPTED. - Ex. 2. Both Operands happen to be ve
- A 9 28 , B 9 6 gt 0 3 gt. B 0 03
after sign extension - A 9 28 - 71
- B 0 03 03
- -------------
- C 9 31 No End Around Carry Accepted.
-
- 9 31 - 68 (Valid Result)
21The (r-1)s Complement Scheme 16 SUBTRACTION
Operation Examples
- Decimal (Contd.)
- Ex. 3. Operand A is ve but Operand B is ve
- A 0 28 B 9 6 gt 0 3 (9s Complement gt
0 03 after sign extension - A 0 28
- B 0 03
- ---------------
- C 0 31 No End around Carry
valid sign ACCEPTED. - Ex. 4. Operand A is -ve but Operand B is ve
- A 9 01 , B 0 6 gt 9 3 gt. B 9 93
after sign extension - A 9 01 - 98
- B 9 93 - 06
- -------------
- C 1 8 94 PLUS ( End Around Carry 1) 8
95 Invalid Sign OVERFLOW -
-
22The (r-1)s Complement Scheme 17 SUBTRACTION
Operation Examples
- Binary Assume n4 (including sign bit)
- Ex. 1. Both operands happens to be ve
- A 0 101, B 011 gt 1s Complement 100
gt1100 after sign extension - A 0 101
- B 1 100
- ---------------
- C 10 001 PLUS End around Carry 1
0010 valid sign ACCEPTED. - Ex. 2. Both operands happens to be -ve
- A 1 110 , B 1 01i.e. B 1 101 after
sign extension - A 1 110 - 1 (Decimal)
- B 1 101 - 2 (Decimal)
- -------------
- C 1 1 011 PLUS (End Around Carry 1)
1100 Accepted. -
- 1100 - 3 (Decimal) valid
23The (r-1)s Complement Scheme 18 SUBTRACTION
Operation Examples
- Binary (Contd.)
- Ex. 3 . Operand A is ve but Operand B is ve
- A 0 101 B 101 gt 1s Complement of B
010gt 0 010 (after sign extension) - A 0 101
- B 0 010
- ---------------
- C 00 111 No end around Carry , Result sign
does not change ACCEPTED. - Ex. 4. Operand A is ve while Operand B is ve
- A 1 101 , B 0 110 gt 1s Complement of B
1 001 - A 1 101
- B 1 001
- -------------
- C 1 0 110 PLUS (End Around Carry 1) 0
111. Result sign changes OVERFLOW..
24The (r)s Complement Scheme - 1
- 10s Complement in Decimal ( Base r 10)
- 2s Complement in Binary ( Base r 2)
- 8s Complement in Octal ( Base r 8)
- Fs / 16s Complement in Hex (Base r 16)
- Rule 1
- (1) For ve numbers represent the sign by
- leading / leftmost 0.
25The (r)s Complement Scheme - 2
- Rule 2 For -ve numbers
- (1) Represent the ve number first (including
sign) by employing leading / leftmost 0. - (2) Subtract each digit of this ve number
representation (including the sign digit) - from (r-1) i.e. the Largest Digit of the
corresponding base / radix ri.e. obtain (r-1)s
complement. - (3) Add 1 to the (r-1)s complement and Ignore
ALL carry.
26The (r)s Complement Scheme - 3
- Examples
- a) 123 in Decimal .
- Applying Rule 1 123 0123
- Using Rule 2 -123 (9999 0123) 9876
- Using Rule 3 98761 9877 gt 10s
Complement.Leading 9 gt -ve - b) 1101 in Binary .
- Applying Rule 1 1101 01101
- Using Rule 2 -1101 (11111 01101) 10010
- Using Rule 3 10010110011 gt 2s Complement
.Leading 1 gt -ve. - c) 12A6 in Hex .
- Applying Rule 1 12A6 012A6
- Using Rule 2 3 -12A6 (FFFFF 012A6) 1
FED5A .Leading F gt -ve
27The (r)s Complement Scheme - 4
- Single representation of 0
- e.g. 00 gt 0 in any base.
- 99 1gt 0 in Decimal , 111 gt 00 in
Binary, - FF1 gt 0 in Hex, 771 gt 0 in Octal .
- Range of Values that can be represented using
n digits (including the sign digit) in base / - radix r
- -r n . r n 1
28The (r)s Complement Scheme 5(The Range of
Values )
- Assuming n (no. of digits) 3 in any base
including sign digit - (a) Decimal System
- Maximum value 10 (3) 1 10 3 1 gt1000 1
gt0 999 - Minimum value -10 3 -1000 9000
- (b) Binary System
- Maximum value 2 3 1 gt 7 (Decimal) gt
0111 - Minimum value 2 3 gt -8 (Decimal) gt 1000
29The (r)s Complement Scheme 6A(The Sign
Extension Rule)
- Given An m digit number (in any base) expressed
in rs complement scheme. - Required
- To express its equivalent in n digits where (ngtm)
. - Rule 1. Treat the given m digit number as the
rightmost / least significant m digits of the
larger n digit number. The sign digit will occupy
the leftmost position of this n digit stream. - Rule 2. Copy / Extend the sign digit in the
leftmost (n-m) digit positions . The leftmost
digit will be treated as the sign digit for the
larger n digit number.
30The (r)s Complement Scheme 6B(The Sign
Extension Rule) Example
- Example 1
- A 4 digit ve decimal number 0105
- Its equivalent in 6 digits 00 0105.
- A 4 digit -ve decimal number 9105
- Its equivalent in 6 digits 99 9105.
- Example 2
- A 4 bit ve Binary number 0101
- Its equivalent in 8 bits 0000 0101.
- A 4 bit -ve decimal number 1110
- Its equivalent in 8 bits 1111 1110.
31The (r)s Complement Scheme 6C(To Calculate
the Value )
- Given an n digit (r)s Complement Number.
Calculate its equivalent value in signed
magnitude scheme. - Rule 1
- For ve numbers / 0 sign do nothing.
- Rule 2
- For ve number i.e. (r-1) sign digit assume
that the sign digit position contains (-1) with
the normal positional weight of r(n-1) . Then
compute the value using positional weights.
32The (r)s Complement Scheme 7(Calculate the
Value Examples)
- Assume n4 (including sign digit ) in any base.
- 1. Decimal 25 gt 025 gt 0025 after sign
extension - -25 gt 10s Complement gt
975 gt 9975 after sign extension - Now 9 975 gt (-1) X 10 (4-1) 9 X 10 (3-1) 7
X 10 (2-1) 5 X 10 (1-1) - gt (-1) X 10 3 9 X 10 2
7 X 101 5 X 10 0 - gt - (1000) 900 705 gt -25
- N.B Each digit of sign extension adds an
additional weight of r (here 10) to the sign
digit i.e. sign digit weight becomes - r n for an n1 digit position from r(n-1)
for its previous n digit position . This
effectively means each digit extension causes the
ve sign to contribute an additional (-r) Hence
to offset this (r-1) digit is to be introduced as
padding so that the - net contribution becomes (-1) X r n
(r-1) X r (n-1)
33The (r)s Complement Scheme 8(Calculate the
Value Examples)
- Assume n4 (including sign digit ) in any base.
- 2. Hex A25 gt 0 A25 , hence -A25 gt Fs
/16s Complement gt F 5DB - Now F 5DB gt (-1) X 16 (4-1) 5 X 16 (3-1)
D13 X 16 (2-1) - B11 X 16 (1-1)
- gt (-1) X 16 3 5 X 16 2
13 X 161 11 X 16 0 - gt - (256 X 16) 5 X 256 20811
- gt -256 X 11 219 gt -(256 X
10 37) - gt -(A X16 2 2 X 16 1 5 X
16 0) gt -A25
34The (r)s Complement Scheme 9(Calculate the
Value Examples)
- Assume n4 (including sign digit ) in any base.
- 3. Binary 11 3 (Decimal) gt 0 11 gt 0
011 after sign extension - -11 -3 (Decimal) gt 2s
Complement of 0011 gt 1 101 - Now 1 101 gt (-1) X 2 (4-1) 1 X 2 (3-1) 0 X
2 (2-1) 1 X 2 (1-1) - gt (-1) X 2 3 1 X 2 2
1X 2 0 - gt - (8) 4 1 gt -3
-
35The (r)s Complement Scheme 10(The Arithmetic
Operations )
- 1) ADDITION C A PLUS B
- Case 1 Both the Operands A B are of same
sign - Step 1 Make A B equal size in terms of no. of
digits (including sign digit) by padding left
side of the smaller operand ( A OR B) with sign
extension i.e. by replicating the sign digit to
the left. - Step 2 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Store ZERO in the
CARRY flag. Check the MSDigit / Sign Digit. If it
is different from the current sign digit of the
two operands, flash overflow else accept result. - Case B. Carry is produced . Store carry in the
carry flag with the generated result. Check the
MSDigit / Sign Digit. If it is different from the
sign of A OR B then flash overflow else accept
result.
36The (r)s Complement Scheme 11 ADDITION
Operation (Contd.)
- Case 2 Operands A B differs in sign
- Step 1 Make A B equal size in terms of no. of
digits (including sign digit) by padding left
side with sign extension i.e. by copying the
sign. - Step 2 Add A B normally along with / including
the sign digit. - Case A. No carry is produced. Store ZERO as
carry out .Accept result - No chance of Overflow .
- Case B. Carry is produced . Store carry digit as
carry out with the generated result. Accept
result No chance of Overflow .
37The (r)s Complement Scheme 12 ADDITION
Operation (examples)
- Assumed n3 i.e. 3 digit decimal number
(including sign) - Decimal Ex. 1. Both Operands happen to be
ve - A 0 28, B 0 6 , B 0 06 (after sign
extension) - A 0 28
- B 0 06
- ---------------
- C 0 34 gt Carry stored 0
Valid sign ACCEPTED. - Ex. 2. Both Operands happen to be -ve
- A -72 999-07219 28 , B -4 99 04
1 96 i.e. - B 9 96 after sign extension
- A 9 28 - 72
- B 9 96 - 04
- -------------
- C 1 9 24 gt Carry Stored 1 Valid Sign
Accepted. -
- Check 9 24 999 924-(751) -76 (Valid
Result)
38The (r)s Complement Scheme 13 ADDITION
Operation (examples)
- Decimal (contd.)
- Ex. 3. Both Operands happen to be ve
- A 0 28 B 0 76
- A 0 28
- B 0 76
- ---------------
- C 1 04 gt Carry stored 0. But
invalid sign OVERFLOW. - Ex. 4. Both Operands happen to be -ve
- A 9 28 , B 9 06
- A 9 28 - 72
- B 9 06 - 94
- -------------
- C 1 8 34 gt 8 34 Carry stored1 but
invalid sign , overflow
39The (r)s Complement Scheme 14 ADDITION
Operation (examples)
- Decimal (Contd.)
- Ex. 5. One Operand (A) is ve while the other
(B) is ve - A 0 28 , B 9 76
- A 0 28 28
- B 9 76 -24
- --------------------
- C 1 0 04 Carry stored 1 , Accepted
- Ex. 6. One Operand (A) is -ve while the other
(B) is ve - A 9 28 , B 0 06
- A 9 28 - 72
- B 0 06 06
- ------------------------
- C 9 34 Carry stored 0 , ACCEPTED
- - 66 Valid Result
40The (r)s Complement Scheme 15 ADDITION
Operation (examples)
- Binary (Assume n 4 bits including SIGN bit)
-
- Ex.1. Both Operands ve
- A 0 101 B 011 gt B 0 011 (After sign
extension) - Rule 1 A 0 101 5 (Decimal)
- B 0 011 3 (Decimal)
- ---------------
- C 1 000 -8 (Decimal). Carry
stored 0. But Result sign (1) differs from the
two Operands sign (0) hence Overflow. - Ex.2. Both Operands -ve
- A 1 110 , B 1 01 i.e. B 1 101 After
sign extension - A 1 110 - 2 (Decimal)
- B 1 101 - 3 (Decimal)
- -------------
- C 1 1 011 Carry stored 1 result sign
does not change Accepted. - 1011 - 5 (Decimal) valid
41The (r)s Complement Scheme 16 ADDITION
Operation (examples)
- Binary (Contd.)
- Ex. 3 . Operand A is ve but Operand B is ve
- A 0 101 B 101 gt B 1 101 (after sign
extension) - A 0 101
- B 1 101
- ---------------
- C 10 010 Carry stored 1 ACCEPTED.
- Ex. 4. Operand A is ve while Operand B is ve
- A 1 101 , B 0 110
- A 1 101
- B 0 110
- -------------
- C 1 0 011 Carry stored 1 ACCEPTED.
-
42The (r)s Complement Scheme 17 SUBTRACTION
Operation
- 1) SUBTRACTION C A MINUS B
- Case 1 Both the Operands A B are of same
sign - Step 1 Obtain (r-1)s complement of B.
- Step 2 Make A B equal size in terms of no.
of digits (including sign digit) by padding left
side of the smaller sized operand (A OR B) with
sign extension i.e. by replicating the sign digit
to the left. - Step 3. Invert Borrow in ( 1 -gt 0 / 0 -gt 1).
- Step 4 Add A , B Borrow in normally along
with / including the sign digit. gt C A PLUS (
B) PLUS ( Borrow In) if there exists no
Borrow originally i.e. Borrow In 0 then (
Borrow In 1) which amounts to producing the rs
complement of B. - Invert the produced borrow( 1 -gt 0 / 0 -gt 1)
and store as Borrow Out. - . Accept result No chance of overflow.
43The (r)s Complement Scheme 18 SUBTRACTION
Operation
- Case 2 Operands A B differs in sign
- Step 1 Obtain (r-1)s complement of B.
- Step 2 Make A B equal size in terms of no.
of digits (including sign digit) by padding left
side of the smaller sized operand (A OR B) with
sign extension i.e. by replicating the sign digit
to the left. - Step 3. Invert Borrow in ( 1 -gt 0 / 0 -gt 1).
- Step 4 Add A , B Borrow in normally along
with / including the sign digit. - Invert the produced borrow( 1 -gt 0 / 0 -gt 1)
and store as Borrow Out. - . Check if result sign is same as that of the
sign of A . If it is same then accept result else
flash overflow.
44The (r)s Complement Scheme 19 SUBTRACTION
Operation Examples
- Decimal Assuming n3 (including sign digit)
- Ex. 1 Both Operands happen to be ve
- A 0 28 B 0 6 gt 9 3 (9s Complement gt
9 93 after sign extension - A 0 28
- B 9 93
- Inv. Borrow 1
- ---------------
- C 1 0 22 Borrow stored In v 1
(0) Result 22 . ACCEPTED. - Ex. 2. Both Operands happen to be ve
- A 9 28 , B 9 6 gt 0 3 gt. B 0 03
after sign extension - A 9 28 - 71
- B 0 03 03
- Borrow 1
- -------------
- C 9 32 Borrow Stored Inv 0 (1)
Result 9 32 Accepted. -
- 9 32 - 68 (Valid Result)
45The (r)s Complement Scheme 20 SUBTRACTION
Operation Examples
- Decimal (Contd.)
- Ex. 3. Operand A is ve but Operand B is ve
- A 0 28 B 9 6 gt 0 3 (9s Complement gt
0 03 after sign extension - A 0 28
- B 0 03
- Borrow 1
- ---------------
- C 0 32 Stored Borrow 1 , Result
0 32 valid sign hence ACCEPTED. - Ex. 4. Operand A is -ve but Operand B is ve
- A 9 01 , B 0 6 gt 9 3 gt. B 9 93
after sign extension - A 9 01 - 99
- B 9 93 - 07
- Borrow 1
- -------------
- C 1 8 94 Stored Borrow 0, Result sign
(8) Invalid OVERFLOW -
-
46The (r)s Complement Scheme 21 SUBTRACTION
Operation Examples
- Binary Assume n4 (including sign bit)
- Ex. 1. Both operands happens to be ve
- A 0 101, B 011 gt 1s Complement 100
gt1100 after sign extension - A 0 101
- B 1 100
- Inv. Bo 1
- ---------------
- C 10 010 Stored Borrow 0, Result
is ACCEPTED. - Ex. 2. Both operands happens to be -ve
- A 1 110 , B 1 01i.e. B 1 101 after
sign extension - A 1 110 - 2 (Decimal)
- B 1 101 - 3 (Decimal)
- Inv. Bo 1
- -------------
- C 1 1100 Stored Borrow Result is accepted.
Since 1100 -3(Decimal) -
47The (r)s Complement Scheme 22 SUBTRACTION
Operation Examples
- Binary (Contd.)
- Ex. 3 . Operand A is ve but Operand B is ve
- A 0 101 B 101 gt 1s Complement of B
010gt 0 010 (after sign extension) - A 0 101
- B 0 010
- ---------------
- C 00 111 No end around Carry , Result sign
does not change ACCEPTED. - Ex. 4. Operand A is ve while Operand B is ve
- A 1 101 , B 0 110 gt 1s Complement of B
1 001 - A 1 101
- B 1 001
- -------------
- C 1 0 110 PLUS (End Around Carry 1) 0
111. Result sign changes OVERFLOW..