🏆 US-Registered Digital Marketing Agency
Advertisement
Advertisement
DEVELOPER

Binary Arithmetic Calculator — add, subtract, multiply, divide

Do arithmetic on two binary numbers and see the carries, borrows and partial products column by column.

Spaces and underscores are ignored, so 0010 1101 and 0010_1101 both work. Anything that is not a 0 or a 1 is rejected.
The bit patterns are identical either way — only the meaning changes. In signed mode a leading 1 makes the value negative, so 11111111 is 255 unsigned and −1 signed.
Working:
Result in the stored word
0
 
0
Decimal (true value)
0
Decimal (as stored)
0
Hexadecimal
0
Flags
Tip: the true value and the stored value differ whenever the result does not fit the word. That difference is what overflow means.
Advertisement

The binary arithmetic calculator above adds, subtracts, multiplies and divides two binary numbers and shows the working out — the carry row on an addition, the borrow row on a subtraction, the shifted partial products on a multiplication and the bit-by-bit steps of a long division. It reports the result in binary, decimal and hexadecimal, and it tells you when the answer did not fit in the word you chose.

Arb Digital publishes this as one of a set of free developer tools. The reason it shows working rather than just an answer is that binary arithmetic is not hard, but it is unfamiliar, and the interesting part is never the sum itself. It is the carry that falls off the end of the register, the borrow chain that ripples the whole width, and the fact that the same bit pattern means two different numbers depending on whether you told the machine it was signed.

What This Binary Arithmetic Calculator Does

It performs the four basic operations on fixed-width binary values, with the width and the signed or unsigned interpretation under your control, and it computes both the mathematically true result and the result as actually stored in that many bits. When those two disagree, it says so and names the flag that a real processor would set.

Two boundaries are worth stating, because there are neighbouring tools on this site and they answer different questions. The number base converter converts a single value between binary, octal, decimal and hexadecimal — it converts, it does not do arithmetic in any base. The bitwise calculator applies AND, OR, XOR, NOT and shifts to two operands, which are logical operations on individual bit positions with no carries between columns at all. This page is specifically about arithmetic, where columns talk to each other.

How to Use It

  1. Type the two operands as bit patterns. Spaces and underscores are ignored, so you can group them in nibbles for readability.
  2. Pick the operation. The working panel changes to match — carries for addition, borrows for subtraction, partial products for multiplication, restoring steps for division.
  3. Choose the word width. Operands are padded or truncated to that width, exactly as they would be in a register of that size.
  4. Choose the interpretation. Unsigned and two's complement give identical bit patterns for addition and subtraction, but different meanings and different overflow conditions.
  5. Read the flags. Carry, borrow and signed overflow are the outputs that actually matter when you are debugging.

The Formula and How It's Calculated

Binary addition is decimal addition with a smaller alphabet. Column by column from the right, 0+0=0, 0+1=1, 1+1=10 — write 0, carry 1 — and 1+1+1=11, write 1, carry 1. Subtraction borrows the same way: 0−1 requires borrowing from the column to the left, and because the columns are worth twice as much each step, the borrow brings a 2 rather than a 10.

Multiplication is easier in binary than in decimal, because every digit of the multiplier is either 0 or 1. Each set bit of B contributes a copy of A shifted left by that bit's position, and the partial products are summed. Division is restoring long division: walk the dividend from the most significant bit, shift each bit into a remainder, and where the remainder is at least the divisor, subtract it and write a 1 in the quotient.

A worked example. A = 00101101 is 45, B = 00010111 is 23. Adding column by column produces carries through the low four columns and gives 01000100, which is 68 — and 45 + 23 = 68, so the arithmetic checks out. The C standard, published in draft as ISO/IEC 9899 working draft N1570, is where the language-level rules on integer types, conversions and overflow behaviour are actually written down, and it is worth reading before relying on any of them.

Advertisement

Signed and Unsigned Are the Same Bits

This is the idea that unlocks everything else. The bit pattern 11111111 is 255 if you agree to read it as unsigned and −1 if you agree to read it as two's complement signed. Nothing about the byte changes. The interpretation lives in the type system and in which instruction you use, not in the memory.

The beautiful consequence is that addition and subtraction hardware does not need to care. Add 11111111 to 00000001 in eight bits and you get 00000000 with a carry out. Read unsigned, that is 255 + 1 = 256 wrapping to 0. Read signed, that is −1 + 1 = 0, which is simply correct. One adder, two valid interpretations — and that is precisely why two's complement won over sign-magnitude and ones' complement representations. Switch the interpretation selector on any addition and watch the binary result stay identical while the decimal reading changes. Our two's complement converter covers the representation itself in more depth.

Carry Is Not Overflow

These two get conflated constantly and they are different flags detecting different failures. Carry means the unsigned result did not fit — a 1 fell off the top of the word. Signed overflow means the two's complement result did not fit, which happens when adding two positives gives a negative, or adding two negatives gives a positive.

Either can occur without the other. Add 11111111 and 00000001 in eight bits: carry is set, signed overflow is not, and the signed answer of 0 is correct. Add 01111111 and 00000001: no carry out, but signed overflow is set, because 127 + 1 produced −128. Processors compute both flags on every addition and let the program decide which one it cares about. The classic detection rule is stated cleanly in Central Connecticut State University's course note on overflow in two's complement: the result is correct when the carry into the high-order column is the same as the carry out of it, and overflow has occurred when they differ.

Word Width Is a Real Constraint, Not a Formatting Choice

Change the width selector from 8 to 16 on a sum that overflowed and the overflow disappears, because the same numbers now fit. That is not the tool being inconsistent — it is the actual behaviour of the machine, and it is the origin of a large family of production bugs. A value that is fine in a 32-bit accumulator wraps in a 16-bit one, and code that works on one platform breaks on another because a type had a different width there.

Multiplication is the sharpest case. Multiplying two 8-bit values can need 16 bits to hold the answer, and multiplying two 32-bit values can need 64. Hardware multipliers usually produce a double-width result for exactly this reason, but many languages will happily truncate it back to the operand width and hand you a wrong number silently. The tool reports both the true product and the stored one so the gap is visible. If you are working with non-integer values, the floating point converter covers a completely different set of representation traps.

Division Is the Awkward One

Integer division discards the fractional part, and the direction it discards in is a genuine source of disagreement. C and most languages that follow it truncate toward zero, so −7 ÷ 2 gives −3 with a remainder of −1. Python floors instead, giving −4 with a remainder of +1. Both are defensible and both are in use, which means porting arithmetic between languages needs care when negatives are involved. This tool truncates toward zero.

Division by zero is not a value you can compute your way out of. In hardware it typically raises a trap rather than returning anything, and in most languages it is an error or undefined behaviour for integers. The tool refuses it rather than inventing a result. Binary long division itself is mechanically simpler than decimal, because at each step the quotient digit is only ever 0 or 1 — you never have to guess how many times the divisor goes in, you just check whether it fits.

Building something where the low-level details matter?

Arb Digital builds web applications and the systems behind them, and we care about the parts that fail quietly. See what we do, or tell us what you are working on.

See Web Design Services Talk to Arb Digital

Common Mistakes to Avoid

  • Confusing carry with signed overflow — they are separate flags, either can fire alone, and only one of them means your signed answer is wrong.
  • Forgetting that the width truncates — a result that does not fit is not an error in most languages, it is a wrong number returned silently.
  • Assuming a product fits the operand width — multiplying two n-bit values can need 2n bits, and many languages will truncate without warning.
  • Expecting one rounding rule for negative division — C truncates toward zero, Python floors, and the remainders have different signs as a result.
  • Reading a bit pattern without knowing its type — 11111111 is 255 or −1, and nothing in the bits themselves tells you which.

Related Free Tools From Arb Digital

Use the number base converter to convert values between bases, the bitwise calculator for AND, OR, XOR and shifts, the two's complement converter for signed representation, the floating point converter for IEEE 754 and the logic gate calculator for the gates underneath. The full free online tools hub lists every calculator we publish.

Frequently Asked Questions

How do you add two binary numbers?

Column by column from the right, carrying into the next column when the total reaches two. 0+0 is 0, 0+1 is 1, 1+1 is 0 carry 1, and 1+1+1 is 1 carry 1. The tool shows the carry row above the sum so the chain is visible.

What is the difference between carry and overflow?

Carry means the unsigned result did not fit the word — a bit fell off the top. Signed overflow means the two's complement result did not fit, which shows up as two positives summing to a negative or two negatives summing to a positive. Either flag can be set without the other.

How do you subtract in binary?

By borrowing, exactly as in decimal, except that a borrow brings 2 rather than 10 because each column is worth twice the one to its right. Hardware usually does it by adding the two's complement of the subtrahend instead, which reuses the adder.

Is 11111111 equal to 255 or to −1?

Both, depending on the interpretation you declare. Unsigned it is 255; as an 8-bit two's complement signed value it is −1. The bits are identical, and only the type tells you how to read them.

How is binary multiplication done?

Each set bit of the multiplier contributes a copy of the multiplicand shifted left by that bit's position, and those partial products are added together. It is simpler than decimal multiplication because every multiplier digit is either 0 or 1, so there is nothing to memorise.

What happens when a result does not fit the word width?

It wraps — the high bits are discarded and what remains is stored. In most languages this happens silently for unsigned types and is undefined behaviour for signed ones. The tool shows the true value and the stored value side by side so the loss is obvious.

How does binary division handle remainders?

Integer division discards the fraction, leaving a quotient and a remainder. This tool truncates toward zero, matching C, so −7 ÷ 2 gives −3 remainder −1. Languages that floor instead, such as Python, give −4 remainder +1 for the same inputs.

This tool demonstrates fixed-width integer arithmetic. Actual behaviour on overflow, division and signed conversion is language and platform specific, and should be confirmed against your language standard.

Advertisement
Advertisement

Take it further