What Is Binary Arithmetic?

What binary arithmetic is and why computers use it, with rule tables for addition, subtraction, multiplication, division and bitwise logic in one place.

Binary Arithmetic: Rules, Tables and Examples

Binary arithmetic works with numbers in the base-2 system, using only the digits 0 and 1. Every calculation a computer performs, from a simple sum to a complex graphics render, reduces to these two symbols. The rules of binary addition, subtraction, multiplication, and division are the foundation, but so are the bitwise operations that manipulate individual bits. The complete reference includes the rule tables, the logic truth tables, the full-adder equations, and the failure cases you will hit in real code.

Binary Numbers and Place Value

In the binary number system, each position holds a power of two, not ten. Reading from the right, the places are 1, 2, 4, 8, 16, and so on. The number 1011 in binary means (1×8) + (0×4) + (1×2) + (1×1), which equals 11 in decimal. The rightmost bit is the least significant bit, or LSB; the leftmost is the most significant bit, or MSB. A byte has eight bits, giving values from 00000000 to 11111111, or 0 to 255 in decimal.

Place value matters because it determines how you read and write binary numbers. A leading zero does not change the value, just as in decimal. The same bit pattern can mean different things depending on context: as an unsigned integer, 11111111 is 255; as a signed two's complement integer, it is -1. You must know the fixed width of the field before you can interpret the bits. That is why hardware and programming languages force you to declare types.

Why Computers Use Base 2

Computers use base 2 because it is physically reliable to distinguish two voltage levels, such as 0 volts and 3.3 volts, than to distinguish ten. A transistor is either on or off, and that on-off state maps directly to a bit. Early computers like the ENIAC used decimal digits in their circuits, but engineers abandoned that approach because drift and noise made ten levels error-prone. Binary arithmetic became standard because a clear threshold exists: below it is 0, above it is 1.

This simplicity carries a cost. Binary numbers are longer than their decimal equivalents, which is why programmers use hexadecimal as shorthand. Each hex digit represents exactly four bits, so 0xF is 1111 and 0xA is 1010. The choice of base is a representation decision, not a mathematical one. The underlying value is the same; only the notation changes. When you see a CPU's instruction set, every operation, from adding registers to testing a flag, is a sequence of binary arithmetic operations.

Rule Tables: Addition, Subtraction, Multiplication, Division

Binary addition has four rules. 0 plus 0 is 0, 0 plus 1 is 1, 1 plus 0 is 1, and 1 plus 1 is 10. The last case produces a carry into the next column, just as 9 plus 1 does in decimal. When you add three ones in a column, as in a full-adder, the result is 11, which is a sum bit of 1 and a carry bit of 1. Subtraction borrows from the next column when you attempt 0 minus 1, giving a result of 1 with a borrow of 1. Multiplication in binary is trivial because each partial product is either the multiplicand or zero, so you shift and add. Division is repeated subtraction, with the quotient bit set when the divisor fits.

OperationRuleExampleResult
Addition0+0=00+00
Addition0+1=10+11
Addition1+1=101+110 (carry 1)
Addition1+1+1=111+1+111 (carry 1)
Subtraction0-0=00-00
Subtraction0-1=1 (borrow 1)0-11 (borrow 1)
Subtraction1-0=11-01
Subtraction1-1=01-10
Multiplication0×0=00×00
Multiplication0×1=00×10
Multiplication1×0=01×00
Multiplication1×1=11×11
Division0÷1=00÷10
Division1÷1=11÷11

These rules apply uniformly, but the carry and borrow behavior is where mistakes happen. In addition, a carry out of the most significant bit signals unsigned overflow, and the carry flag in a CPU records it. In signed arithmetic, a carry out is not the same as overflow; overflow occurs when the sign of the result differs from the sign of both operands. For subtraction, the standard method is to add the two's complement of the subtrahend, which converts the operation to addition and reuses the same adder circuit.

Bitwise Logic Truth Tables: AND, OR, XOR, NOT

Bitwise operations work on each bit position independently. OR yields 1 when at least one input is 1. XOR, short for exclusive OR, yields 1 when exactly one input is 1. NOT inverts every bit, turning 0 into 1 and 1 into 0. These operations are the building blocks of binary arithmetic, because addition itself decomposes into XOR for the sum and AND for the carry.

ABA AND BA OR BA XOR BNOT A
000001
010111
100110
111100

These operations do not vary by platform or language. An arithmetic shift preserves the sign bit, so a right shift of a negative number in two's complement fills with 1s. In C, a right shift of a signed negative integer is implementation-defined, though GCC and Clang choose arithmetic. These equations are not optional theory; they are the literal circuit inside every ALU.

Chain full-adders together to add multi-bit numbers. The carry-out of one stage becomes the carry-in of the next. This ripple-carry design is simple but slow, because the carry must propagate through every stage. The failure case appears when the result does not fit the destination width. If you add two 8-bit numbers and get a 9th bit, the carry flag sets, but the stored result is the low 8 bits. Ignoring that flag produces a wrong answer that is correct in modular arithmetic, which is why unsigned overflow is silent unless you check the flag.

Binary Subtraction and Two's Complement

Instead, subtract by adding the two's complement of the subtrahend. To compute two's complement, invert all bits and add 1. For example, adding 127 and 1 in an 8-bit byte gives -128, which is correct. The overflow flag sets, but the carry flag may not. In C, signed overflow is undefined behavior, so the compiler may assume it never happens and optimize accordingly. In Python, integers are unbounded, so overflow never occurs, but you lose the fixed-width behavior. The rules of binary addition do not change; the width and interpretation do.

When you subtract, the carry flag behaves differently. In most CPUs, subtraction sets the carry flag to indicate a borrow, but the convention varies. On x86, the carry flag is set when the subtrahend is greater than the minuend, meaning a borrow occurred. On ARM, the carry flag is set when no borrow occurs. Knowing this difference prevents subtle bugs when you read the flags after a subtraction instruction.

Binary Multiplication and Division Algorithms

Binary multiplication is shift-and-add. For each 1 bit in the multiplier, shift the multiplicand and add it to the product. For each 0 bit, shift but do not add. The product of two n-bit numbers can take up to 2n bits, so the result width matters. Unsigned multiplication is straightforward, but signed multiplication requires sign-extension of partial products, which is why the Booth algorithm exists: it reduces the number of additions by grouping runs of 1s.

Binary division is repeated subtraction. The quotient bit is set when the divisor fits into the current remainder. The failure case is division by zero, which raises a hardware exception on most CPUs. In C, division by zero is undefined behavior, so the compiler may assume it never happens. In Python, division by zero raises a ZeroDivisionError. Shifting right on a negative number is arithmetic on most compilers, filling with 1s to preserve the sign.

Shifting by the width of the type or more is undefined behavior in C and C++. Shifting a 32-bit integer left by 32 is not defined, even though it seems like it should produce 0. In JavaScript, shifts operate on 32-bit integers, so 1 << 31 is -2147483648, not 2147483648. In Python, shifting left by a negative count raises an error, but shifting right by a negative count is the same as shifting left. These are the corners where binary arithmetic stops being academic and starts costing you bugs.