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!
Best Answer
$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)$.