Search code examples
binarybinary-datasubtraction

What is borrow in and borrow out?


When doing binary subtraction what is the borrow in and borrow out. enter image description here


Solution

  • Binary subtraction works just like decimal subtraction. Subtraction is done column by column, from right to left. For each column, you need to know two things:

    1. Did the previous column need to do a borrow? (borrow in)
    2. Did this column's subtraction need to do a borrow? (borrow out)

    So if we are doing decimal subtraction:

      110
      -98
      ---
    

    For the first column, there is no previous column, so no borrow in. But there is a borrow out - we needed to borrow because 0 < 8. The result is 2.

    For the second column, there is a borrow in from the first column, and a borrow out since 0 < 9. The result is 1.

    For the third column there is a borrow in, but no borrow out (0 >= 0).