Skip to content
FigureSure
Sign in

Binary Calculator

Add, subtract, multiply and divide binary numbers, run bitwise AND, OR, XOR, NOT and shifts, and convert between binary and decimal. Every answer comes with the column working, the decimal check and the two's-complement form for 8, 16, 32 or 64 bits.
  • Updated
  • Formula shown

What do you want to do?
Mode

Also used for NOT

Binary numbers

Digits 0 and 1, up to 256; spaces are ignored

A leading minus is allowed for +, − and ×

Results

A + B
1 0010
= 18 in decimal
Decimal
11 + 7 = 18
Hexadecimal
12
8-bit two's complement
Positive: the same bits with leading zeros
0001 0010

1011 + 111 = 10010 (18 in decimal)

Working
Add each column from the right: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), 1 + 1 + 1 = 11 (write 1, carry 1).

carry   1111
         1011
      +   111
        ─────
        10010

Result: 10010
Check in decimal: 11 + 7 = 18

How to use the binary calculator

  1. Choose Calculate for arithmetic and bitwise operations, or Convert for binary ↔ decimal.
  2. Type binary numbers using only 0 and 1. Spaces are ignored, so 1111 1011 is fine, and a 0b prefix is allowed. For +, − and × a leading minus sign is accepted.
  3. Pick the operation. For shifts, enter how many places; for NOT, the bit width decides how many bits are flipped.
  4. Choose a bit width to see the result in two's complement, the form computers use for signed integers.

Inputs can have up to 256 bits (or 78 decimal digits), and all arithmetic is exact. The column layout is drawn for numbers up to 64 bits; longer inputs still get exact answers.

Binary formulas

Value of bₖ…b₂b₁b₀ = bₖ × 2k + … + b₂ × 2² + b₁ × 2¹ + b₀ × 2⁰
Shift left by n: A × 2n  ·  shift right by n: A ÷ 2n, rounded down
Two's complement of −x in w bits: 2w − x (flip the bits of x, then add 1)

Binary is base 2: each digit (a bit, b₀ on the right) is 0 or 1, and each place is worth twice the place to its right. The arithmetic rules are the same as in decimal, but a column overflows at 2 instead of 10, so 1 + 1 is written 10 with a carry. Two's complement stores a negative number −x in w bits as 2w − x, which lets a computer subtract by adding.

Worked examples

Addition: 1011 + 111

carry   1111
         1011
      +   111
        ─────
        10010

From the right: 1 + 1 = 10, write 0 and carry 1; 1 + 1 + 1 = 11, write 1 and carry 1; 0 + 1 + 1 = 10, write 0 and carry 1; 1 + 1 = 10. The answer is 10010, and in decimal 11 + 7 = 18.

Subtraction: 1011 − 111

borrow  1
        1011
      −  111
        ────
         100

The third column from the right needs a borrow: the leftmost 1 lends to it, which turns 0 − 1 into 10 − 1 = 1. The result, 100, is 11 − 7 = 4.

Converting 1101 to decimal, and 13 back to binary

1101₂ = 1 × 2³ + 1 × 2² + 0 × 2¹ + 1 × 2⁰ = 8 + 4 + 0 + 1 = 13₁₀. Going the other way, divide by 2 and keep the remainders:

  1. 13 ÷ 2 = 6 remainder 1
  2. 6 ÷ 2 = 3 remainder 0
  3. 3 ÷ 2 = 1 remainder 1
  4. 1 ÷ 2 = 0 remainder 1

Reading the remainders from the last to the first gives 1101.

−5 in 8-bit two's complement

Write 5 in 8 bits, 0000 0101; flip every bit, 1111 1010; add 1: 1111 1011. Reading that pattern back as a signed 8-bit number gives −5, because the top bit counts as −128 instead of +128.

Bitwise: 1100 and 1010

1100 AND 1010 = 1000, 1100 OR 1010 = 1110, and 1100 XOR 1010 = 0110.

Powers of 2

PowerDecimalBinary
2011
21210
224100
2381000
24161 0000
253210 0000
2664100 0000
271281000 0000
282561 0000 0000
2101,024100 0000 0000
2124,0961 0000 0000 0000
21665,5361 0000 0000 0000 0000
2201,048,5761 0000 0000 0000 0000 0000
22416,777,2161 0000 0000 0000 0000 0000 0000
2312,147,483,6481000 0000 0000 0000 0000 0000 0000 0000
2324,294,967,2961 0000 0000 0000 0000 0000 0000 0000 0000

8-bit two's complement

Decimal8-bit pattern
1270111 1111
640100 0000
50000 0101
10000 0001
00000 0000
−11111 1111
−51111 1011
−641100 0000
−1271000 0001
−1281000 0000

Tips and common mistakes

  • Group bits in fours. Each group of 4 bits is one hexadecimal digit, which makes long binary numbers easier to read and check. The hex calculator converts between the two.
  • Overflow. In 8 bits, 127 + 1 gives the pattern 1000 0000, which a signed 8-bit number reads as −128. The calculator flags results that only fit as unsigned.
  • Right shifts lose bits. 1011 >> 2 is 10: the remainder of 11 ÷ 4 is thrown away.
  • NOT depends on the width. NOT 1011 is 0100 in 4 bits but 1111 0100 in 8 bits, so always say how many bits you mean.

Frequently asked questions

How do you add binary numbers?

Add column by column from the right, using 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). For example, 1011 + 111 = 10010, which is 11 + 7 = 18 in decimal.

How do you convert binary to decimal?

Multiply each bit by its place value, a power of 2 that doubles from right to left (1, 2, 4, 8, …), and add the results. 1101 = 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 13.

How do you convert decimal to binary?

Divide by 2 repeatedly and write down each remainder, then read the remainders from the last to the first. For 13: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 = 1101 in binary.

What is two's complement?

It is how computers store negative whole numbers in a fixed number of bits. To write −5 in 8 bits, write 5 as 00000101, flip every bit to get 11111010, then add 1: 11111011. An 8-bit signed number ranges from −128 to 127, and the top bit is 1 for every negative value.

What do AND, OR and XOR do?

They compare two numbers bit by bit. AND gives 1 only where both bits are 1, OR gives 1 where either bit is 1, and XOR gives 1 where the bits differ. For 1100 and 1010: AND = 1000, OR = 1110 and XOR = 0110.

Was this calculator helpful?