Search code examples
binarybitsubtraction

Binary Subtraction Borrowing Logic for 1000 - 0110?


I am having a hardtime understanding the borrowing logic for 1000 - 0110 . I know the answer would be 0010 but I am having trouble understanding the borrowing part a little.

First Step is Ok 0 - 0 = 0

1000
0110
----
   0

Second Step 0 - 1 , so we need to borrow . We borrow 1 and as result 10 - 1 = 1

   ->1
    1000
    0110
    ----
      10

But at the next step there is nothing to borrow, so how does it work ?


Solution

  • When you borrow, you carry over binary 10 to the lower bit, so:

      0
    ->1
     0000
     0110
     ----
        0 
    

    Then you borrow again, and subtract 1 from 10, which is 1:

       0
    ->11
     0000
     0110
     ----
        0 
    

    And finally:

       0
    ->11
     0000
     0110
     ----
     0010