I'm trying to figure out how to subtract two binary numbers with a complementary one or two, When I need to address carrier and when not? Do I need to solve the problem in decimal numbers? And simultaneously see the answer in binary numbers? For example:
(10101010) - (1101101) complement of (1101101) is 0010010 then i take the first number and add it to the complement 10101010+ 0010010 _______ 10111100 the result of subtraction those number is : 111101 so what i`m understanding is i have a carrier so i`m take 111100 + 1 and i get the final result : 111101 now I`ll take another two numbers
(111001) - (10011) i`m doing the same procces and i dont get the right answer. what should i do? Do I need to complete the number to the eight bits? That is if you need to add zeros then the complement they will become one?
Thanks!
2 Answers
$\begingroup$$10101010 - 1101101 = 10101010 - 01101101 = 10101010 + (-01101101)= 10101010 + (10010010 + 1)=10101010 + 10010011 = 00111101$
And you can check that $00111101+1101101=10101010$
$111001 - 10011 = 00111001 - 00010011 = 00111001 + (-00010011) = 00111001 + (11101100 + 1) = 00111001 + 11101101 = 00100110$
And you can check that $00100110+10011=111001$
So to compute $a-b$, you start by making sure you have $8$ bits for both numbers and add $0$s on the left otherwise, then you compute $-b$ by negating all the bits and adding $1$ and then you compute $a+(-b)$.
$\endgroup$2$\begingroup$You cannot add by just taking complement of a number.First you have to convert negative number into 2's complement.
2's complement First take complement add 1 to flipped number
a=(010101010) - b=(001101101)
2's complement of b is 110010011
now $a+b^{'}$
$\endgroup$1a= 010101010 (170)
$b^{'}$=110010011 (-109)
c= 000111101 (61)