Binary Calculator

Add, subtract, multiply and divide binary numbers, run AND, OR, XOR, NOT and shifts, and see each result in decimal, hex and octal with the working shown.

Perform calculations with binary numbers: addition, subtraction, multiplication, division (quotient and remainder), bitwise AND, OR, XOR, NOT and shifts. Inputs and results are also shown in decimal, hexadecimal and octal. Enter whole binary numbers only (0 and 1); binary fractions such as 101.11 are not supported.

Binary Operation

Display Options

Binary Calculator: Add, Subtract, Multiply, Divide

Binary is the base-2 numeral system representing values using only the digits 0 and 1, forming the fundamental language of all digital computers. A common mistake is to think binary is a 'language' of switches; it is a mathematical notation for numbers, and the switches are just the physical implementation. The real subject is the arithmetic and representation rules that let you convert, add, subtract, multiply, divide, and interpret bit patterns correctly across different hardware and programming languages. This binary calculator performs calculations with binary numbers: addition, subtraction, multiplication, division (quotient and remainder), bitwise AND, OR, XOR, NOT and shifts. Inputs and results are also shown in decimal, hexadecimal and octal.

  • Base-2 digit set: 0, 1
  • Binary place value: 2^n, n = position from right starting at 0
  • Largest 8-bit unsigned value: 255
  • 8-bit signed two's complement range: -128 to 127
  • 16-bit unsigned range: 0 to 65535
  • 32-bit unsigned range: 0 to 4294967295
  • 64-bit unsigned range: 0 to 18446744073709551615
  • Two's complement negation: Invert all bits, add 1

How to Use the Binary Calculator

Select an operation from the dropdown menu: Addition (+), Subtraction (−), Multiplication (×), Division (÷), Bitwise AND (&), Bitwise OR (|), Bitwise XOR (^), Bitwise NOT (~), Left Shift (<<), or Right Shift (>>). Enter whole binary numbers only (0 and 1); binary fractions such as 101.11 are not supported. For NOT and shifts, a single binary number is required. For shifts, also enter a shift amount (0 to the bit width). Choose a bit width (4-bit, 8-bit, 16-bit, 32-bit, 64-bit) for NOT, shifts, overflow detection, and two's complement interpretation. For right shifts, select Logical (fill with 0s) or Arithmetic (copy the sign bit). Click Calculate to see the result in binary, decimal, hexadecimal, and octal. Click Show Calculation Steps to view the working. Use Reset to start over.

Signed Vs Unsigned Interpretation

For arithmetic operations, the calculator treats inputs as unsigned and shows the result in decimal, hex, and octal. If the result exceeds the chosen bit width, it notes overflow. For subtraction that yields a negative result, the calculator shows the two's complement representation within the selected width. For bitwise operations, the calculator performs the operation on the unsigned bit patterns. The signed interpretation of the result is shown separately in the notes.

Arithmetic Operations

Addition: Add two binary numbers following the rules 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1). Subtraction: Use borrowing when necessary. Multiplication: Multiply binary numbers similar to decimal multiplication. Division: Divide binary numbers similar to long division in decimal; the calculator shows the quotient and remainder.

Bitwise Operations

AND (&): Returns 1 if both bits are 1, otherwise 0. OR (|): Returns 1 if at least one bit is 1, otherwise 0. XOR (^): Returns 1 if bits are different, 0 if they are the same. NOT (~): Inverts all bits (1 becomes 0, 0 becomes 1) within the chosen bit width. Left Shift (<<): Shifts bits to the left, filling with 0s; bits pushed past the bit width are lost (overflow). Right Shift (>>): Shifts bits to the right; a logical shift fills with 0s, an arithmetic shift copies the sign bit.

Binary Addition Calculator

The binary addition calculator performs addition of two binary numbers. For example, 0101 + 0011 = 1000 (decimal 5 + 3 = 8). The rules are simple: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (write 0, carry 1). Verify this by converting to decimal: 0101 is 5, 0011 is 3, 5+3=8, and 1000 is 8. For a 4-bit signed interpretation, 0111 + 0001 = 1000 (decimal 7 + 1 = 8) produces overflow because 8 exceeds the maximum 4-bit signed value of 7, and the result is interpreted as -8 in two's complement. The carry flag indicates unsigned overflow; the overflow flag indicates signed overflow. A single addition can set both flags independently.

Binary Subtraction Calculator

The binary subtraction calculator subtracts one binary number from another. For example, 0101 - 0011 = 0010 (decimal 5 - 3 = 2). The rule is 0 - 1 gives 1 after borrowing from the next left bit. Verify by converting to decimal: 0101 is 5, 0011 is 3, 5-3=2, and 0010 is 2. For negative results, the calculator uses two's complement within the chosen bit width. For instance, 0011 - 0101 = 1110 (decimal 3 - 5 = -2, represented as 1110 in 4-bit two's complement). Two's complement negation: invert all bits and add 1.

Binary Multiplication Calculator

The binary multiplication calculator multiplies two binary numbers. For example, 0011 * 0010 = 0110 (decimal 3 * 2 = 6). Each bit in the second number multiplies the first, then the partial products are added, similar to decimal multiplication. Verify by converting to decimal: 0011 is 3, 0010 is 2, 3*2=6, and 0110 is 6. The calculator handles signed multiplication by interpreting inputs as unsigned and showing the result; for two's complement signed multiplication, the result is the same for positive operands. For example, 101 (decimal 5) * 011 (decimal 3) = 1111 (decimal 15) in 4-bit unsigned, but in 4-bit signed, 101 is -3, 011 is 3, and the product -9 overflows.

Binary Division Calculator

The binary division calculator divides one binary number by another, showing the quotient and remainder. For example, 0110 / 0010 = 0011 (decimal 6 / 2 = 3) with remainder 0. The process follows the same long division as decimal, but using binary digits. Verify by converting to decimal: 0110 is 6, 0010 is 2, 6/2=3, and 0011 is 3. For 1001 / 0010, the quotient is 0100 (decimal 4) and the remainder is 0001 (decimal 1). The calculator does not support fractional results; division is integer division truncating toward zero. Division by zero is undefined and returns an error.

Binary Arithmetic Rules at a Glance
OperationRuleExampleDecimal Check
Addition0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1)0101+0011=10005+3=8
Subtraction0-1=1 (borrow 1)0101-0011=00105-3=2
MultiplicationEach bit in multiplier multiplies the multiplicand, partial products summed0011*0010=01103*2=6
DivisionLong division in base-20110/0010=00116/2=3
Bitwise AND1&1=1, else 01010&1100=100010&12=8
Bitwise OR1|1=1, 1|0=1, 0|0=01010|1100=111010|12=14
Bitwise XOR1^0=1, 0^1=1, 0^0=0, 1^1=01010^1100=011010^12=6
Bitwise NOT~0=1, ~1=0 (within bit width)~1010 (4-bit)=0101~10=-11 (signed)
Left ShiftShift left, fill with 0s, overflow at MSB1010<<1=010010<<1=4 (4-bit)
Right Shift (Logical)Shift right, fill with 0s1010>>1=010110>>1=5 (unsigned)
Right Shift (Arithmetic)Shift right, fill with sign bit1010>>1=1101-6>>1=-3 (4-bit signed)

Worked Example: Binary Addition and Bitwise AND

These worked examples show the step-by-step process. Verify all worked examples by converting to decimal.

Binary Addition: 1010 + 0110

Input: 1010 (10 decimal) + 0110 (6 decimal). Step 1: Align numbers. 1010 and 0110. Step 2: Add bit by bit from LSB: 0+0=0, 1+1=0 carry 1, 0+1+carry=0 carry 1, 1+0+carry=0 carry 1, carry 1 to new column. Result: 10000 (16 decimal). Check: 10+6=16.

Bitwise AND: 1010 & 1100

Input: 1010 (10 decimal) and 1100 (12 decimal). Step 1: Align bits: 1010, 1100. Step 2: Apply AND rule: bit 3: 1&1=1, bit 2: 0&1=0, bit 1: 1&0=0, bit 0: 0&0=0. Result: 1000 (8 decimal). Check: 10&12=8.

Reading the Result in Decimal, Hex and Octal

After calculation, the binary result is shown alongside its decimal, hexadecimal and octal equivalents. For example, binary 10000 is decimal 16, hex 0x10, octal 0o20. The input values are also shown in these systems in the Input Values table. Use the decimal value to verify your hand calculations; use hex for memory addresses and machine code; use octal for file permissions (e.g., chmod).

Common Questions

What is the difference between a carry flag and an overflow flag?

The carry flag indicates unsigned overflow: the result does not fit in 0 to 2^N-1. The overflow flag indicates signed overflow: the result does not fit in -2^(N-1) to 2^(N-1)-1.A single addition can set both flags independently.

Why does Python's -1 >> 1 equal -1, but -1 & 0xFF equal 255?

Python emulates infinite-precision two's complement. Right shift (>>) is arithmetic: it preserves the sign bit, so -1 >> 1 is -1. Bitwise AND (&) with a mask (0xFF) truncates the infinite sign-extension: -1 is ...11111111, AND 0xFF gives 0xFF (255). Python has no fixed-width integers, so overflow never occurs. This confuses newcomers because the same bit pattern (0xFF) represents -1 as signed and 255 as unsigned.

What is the difference between logical and arithmetic right shift?

Logical right shift (>>> in JavaScript) fills the vacated bits with zeros. Arithmetic right shift (>> in most languages) fills with the sign bit (the most significant bit). For unsigned values, both are identical. For signed negative values, arithmetic shift preserves the sign, dividing by two; logical shift treats the value as unsigned. In C, right shift of a negative signed value is implementation-defined (C17 6.5.7). GCC and Clang use arithmetic shift.

How do I verify my hand-calculated binary answer without a calculator?

Convert every binary number to decimal, perform the operation in decimal, then convert the result back to binary. For addition: 0101 (5) + 0011 (3) = 1000 (8). For subtraction: 0101 (5) - 0011 (3) = 0010 (2). For multiplication: 0011 (3) * 0010 (2) = 0110 (6). For division: 0110 (6) / 0010 (2) = 0011 (3). This cross-check catches errors in carry/borrow and bitwise logic.

How do I convert a negative decimal number to binary by hand?

Use two's complement. For -3 in 4-bit: write +3 as 0011, invert all bits to get 1100, add 1 to get 1101. That is -3. The rule 'invert and add one' works because -x = (~x) + 1 in two's complement. The most significant bit has a negative weight: for 4-bit, the MSB is -8, so 1101 = -8 + 4 + 0 + 1 = -3. For -8, 1000 is -8; for -1, 1111 is -1.

Guides on this site