DEV Community

Eduard Grigoryan
Eduard Grigoryan

Posted on

Binary number subtraction, multiplication

SUBTRACTION

To subtract two binary numbers we write them over each other such that the rightest digits are over each other. If the upper digit is 1 and the lower digit is 0 then at the bottom we write 1 because 1-0=0, if the top digit is 0 and the bottom one is 1 then we have to borrow from the columns to the left, we borrow 1 from the first column to the left and the 1 becomes 0 and the 0 that we borrowed the one for becomes 1 and we write 0 at the bottom, because 1-1=0.

 ,
 101
-
  10
 ____
  11
Enter fullscreen mode Exit fullscreen mode

The coma over the last 1 means that we are borrowing from it because in the second column the upper digit is 0 which is smaller then the lower digit which is 1.

If the top number is bigger then the lower number then computers usually add another bit to the left which will indicate that the final number is negative. If the leftest bit is 0 that means the number is positive because when we add a 0 to the left if our number the number doesn't change, but if the bit is 1 the computer will understand that the number is negative.

MULTIPLICATION

I will explain the multiplication with an example. You can solve other problems using the same logic.
So i want to multiply the number 1101 with 11. To do the multiplication we need to write the numbers like we did with the subtraction, such that the rightest did it of the top number is on the top of the rigtest digit of the lower number.
Then we multiply the top number with the rightes digit of the lower number and we writ it on the bottom line, then we multiply the top number by the second digit of the lower number, but we will write it on the bottom after leaving the space for the first digit open, like it is shown below.

 1101
x
   11
Enter fullscreen mode Exit fullscreen mode

 1101
Enter fullscreen mode Exit fullscreen mode

+
1101


100111

After doing the multiplication and writing the numbers the way it is shown above, we will just need to add those numbers together to get the result.

That's all thanks for reading

Top comments (0)