If A and B are positive numbers calculate AB assuming a ones
If A and B are positive numbers, calculate A-B assuming a one\'s complement number system and n=8; A=101010 and B=1010.
Solution
What is one\'s complement?
It is a number system to store negative values by putting flag(1) in Most Significant Bit(MSB) and complementing the other bits while storing negative numbers. For example,
NOTE: Assuming A and B both as positive numbers as given in the question.
To computer A-B, actually we will be doing A+(-B).
A
+(-B)
1 0 1 0 1 0
1 1 0 1 0 1
42
+(-10)
(011111) + (000001)
= 100000
Step 1: Binary and Decimal value representation of A.
Step 3: Binary and Decimal value representation of B.
Step 3: To do this we change all the 1\'s to 0\'s and 0\'s to 1\'s. Notice that the most-significant digit is now 1 since the number is negative.
Step 4: Re-writing values of A and -B again for better understanding.
Step 5: Performing Binary addition of A and -B. This resulted into overflow bit. In the case of overflow, we have to add 1 to the value.
Step 6: Adjusting overflow value by adding it to the result. Result is 100000.
| NUMBER | ONE\'S COMPLEMENT REPRESENTATION |
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| -7 | 1000 |
| -6 | 1001 |
| -5 | 1010 |
| -4 | 1011 |
| -3 | 1100 |
| -2 | 1101 |
| -1 | 1110 |

