Binary Borrow Calculator – Free

This binary borrow calculator subtracts one binary number from another and lists the borrow into and out of every bit position, starting at the least significant bit.

How to use the Binary Borrow Calculator tool

  1. Enter the number to subtract from in the First binary number box.
  2. Enter the number being subtracted in the Second binary number box. Example loads 1011 and 11.
  3. Select Show steps to run the subtraction.
  4. Read the Result line for the difference, then the Bit lines below it. Bit 0 is the rightmost column.
  5. Select Copy to copy the whole trace, or Clear to try other operands.

How borrowing works in binary subtraction

Subtract column by column from the right. When the top bit is at least as large as the bottom bit plus any borrow owed, the column resolves on its own. When it is smaller, the column borrows from the next position to the left. A borrowed 1 is worth two in the current column, exactly as a borrowed 1 is worth ten in decimal.

A borrow can ripple. In 1000 - 1, bit 0 needs to borrow, but bits 1 and 2 are zero and have nothing to lend, so each passes the request along until bit 3 pays.

Reading the binary borrow calculator trace

Each line has the form Bit n: a − b, in x, out y. The first number is the bit of the first operand in that column, the second is the bit of the second operand, in is the borrow arriving from the column to the right, and out is the borrow this column passes to the left. The shorter operand is padded with leading zeros so both have the same number of columns.

The trace does not print the difference bit for each column. Read it from the Result line at the top.

First: 1000   Second: 1

Result: 111

Bit 0: 0 − 1, in 0, out 1
Bit 1: 0 − 0, in 1, out 1
Bit 2: 0 − 0, in 1, out 1
Bit 3: 1 − 0, in 1, out 0

When the second number is larger

If the second operand is greater than the first, the last line ends with out 1. That final borrow has no column to come from. In hardware it becomes the borrow flag, and the bits left in the register are the answer in two's complement form.

The calculator handles this by showing the mathematical result with a minus sign. For 11 - 1011, the Result line reads -1000, and the trace still shows the borrow leaving bit 3.

The logic behind each line: a full subtractor

Every line of the trace is one full subtractor, the circuit that subtracts two bits and an incoming borrow. Its difference output is a XOR b XOR in. Its borrow output is 1 when the column comes up short: when a is 0 and b is 1, or when a equals b and a borrow came in. Real processors usually skip this circuit and add the two's complement of the second operand instead.

Input rules for the borrow trace

Both boxes accept 1 to 65,536 binary digits. Spaces are removed and a 0b prefix is ignored, so grouped input such as 1011 0110 is fine. Minus signs are not accepted here, because the trace works on raw bit columns. The Binary Subtraction Calculator takes signed operands but shows no trace. A minus sign or any other stray character returns Enter between 1 and 65,536 binary digits. The Result line has no leading zeros. The trace is generated in your browser.

Frequently asked questions

What is a borrow in binary subtraction?

It is a 1 taken from the next higher bit when a column cannot be subtracted as it stands. The borrowed 1 counts as two in the current column, so 0 - 1 with a borrow becomes 10 - 1 = 1.

Why does the page example show no borrows?

The Example values are 1011 and 11. In every column the top bit is at least as large as the bottom bit, so nothing is borrowed and every line reads out 0. Try 1000 and 1 to see a chain.

What does out 1 on the last line mean?

The subtraction needed a borrow from beyond the most significant bit, which means the second number is larger than the first. The Result line shows a negative value in that case.

Does a CPU set a flag for the final borrow?

Yes, though conventions differ. On x86 the carry flag is set to 1 when a subtraction borrows. On ARM the carry flag is the inverse: it is cleared when a borrow occurs and set when it does not.

Related tools