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?
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?
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.