A and B are two 8-bit 2’s complement numbers. The result of
A & B is 10011000
and the result of
A ^ B is 00100110.
(a) What is the sum
A + B
expressed in 8-bit two’s complement notation (use 1s and 0s, e.g. 10100101)?
Will the carry flag be set?
Will the overflow flag be set?
Given A&B = 10011000 (A and B) -Eqn 1
and A^B = 00100110 (A XOR B) - Eqn 2
Now, from these 2 equations, we will find the value of A and B, then we will calculate its sum(A+B).
We will proceed bit by bit starting from left to right-
Bit 1 - A&B is 1 means both A and B bit should be 1
Bit 2- A^B is 0 means both A and B bit should be the same(0 or 1), and A&B is 0. So A and B's bit will be 0
Bit 3 - A^B is 1 means both A and B bit is different. A&B is 0. So either of the combinations follows - A-0/1, B-1/0
Bit 4- A&B is 1 means both A and B bit should be 1
Bit 5 - A&B is 1 means both A and B bit should be 1
Bit 6 - A^B is 1 means both A and B bit is different. A&B is 0. So either of the combinations follows - A-0/1, B-1/0
Bit 7 - A^B is 1 means both A and B bit is different. A&B is 0. So either of the combinations follows - A-0/1, B-1/0
Bit 8 - A^B is 0 means both A and B bit should be the same(0 or 1), and A&B is 0. So A and B's bit will be 0
Now, A and B will look like -
A = 1 0 1/0 1 1 1/0 1/0 0
B = 1 0 0/1 1 1 0/1 0/1 0
Here the order of 0/1 should be followed. If A is taken as 1 then B should be 0 and vice versa.
Now, the sum A+B will be as expressed in 2's complement notation -
A+B = 0 1 0 1 0 1 1 0, with a carry of 1
Yes, the carry flag will be set as the addition of the two numbers caused a carry to occur.
Yes, the overflow flag will be set, as addition of 2 signed bit numbers with leftmost bit 1 has caused the answer with leftmost bit to be 0. Leftmost bit 1 indicates negative number, and 0 indicates positive. Overflow means answer is not correct. Here, addition of 2 negative numbers caused overflow and rounded off to a positive number. So the overflow flag will be set.
Get Answers For Free
Most questions answered within 1 hours.