Do 79-42 in binary using 2's Complement

769 Views Asked by At

I did:

79_10 = 1001111

42_2 = 101010

I took 2's Complement of 42 and got 010110. Then I did 1001111 + 010110 and got 1100101 but this is 101. If I remove the leftmost one it becomes 37 which is correct... where did it go wrong?

2

There are 2 best solutions below

4
On BEST ANSWER

When doing 2's complement, you have to decide beforehand exactly how many bits you have, and then use that many bits, nothing more, nothing less, for any number in your calculation.

To be able to calculate with $79$, you need at least $8$ bits. So let's go for $8$ bits. Then $$ 79_{10} = 01001111_2\\ 42_{10} = 00101010_2 $$ So with $2$'s complement, we get $$ -42_{10} = 11010110_2 $$ Now we can add the two to get $$ \begin{array}{cc} &01001111\\ +&11010110\\ \hline=&00100111 \end{array} $$ with a carry that disappears. So the end result is $$ 00100111_2 = 37_{10} $$ as expected.

2
On

Let us make the computations in a parallel manner, bases ten and two: $$ \begin{aligned} &79-42 \\ &= 79+(64-42)-64 \\ &=79+22-64 \\ &=101-64 \\ &=37\ . \end{aligned} \qquad \begin{aligned} &1001111-101010 \\ &=1001111+010110-1000000 \\ &=1100101-1000000 \\ &=100101\ . \end{aligned} $$