Binary Calculator
- Updated
- Formula shown
- Free, no sign-up
Results
1011 + 111 = 10010 (18 in decimal)
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 = 18How to use the binary calculator
- Choose Calculate for arithmetic and bitwise operations, or Convert for binary ↔ decimal.
- Type binary numbers using only 0 and 1. Spaces are ignored, so
1111 1011is fine, and a0bprefix is allowed. For +, − and × a leading minus sign is accepted. - Pick the operation. For shifts, enter how many places; for NOT, the bit width decides how many bits are flipped.
- 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
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:
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 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
| Power | Decimal | Binary |
|---|---|---|
| 20 | 1 | 1 |
| 21 | 2 | 10 |
| 22 | 4 | 100 |
| 23 | 8 | 1000 |
| 24 | 16 | 1 0000 |
| 25 | 32 | 10 0000 |
| 26 | 64 | 100 0000 |
| 27 | 128 | 1000 0000 |
| 28 | 256 | 1 0000 0000 |
| 210 | 1,024 | 100 0000 0000 |
| 212 | 4,096 | 1 0000 0000 0000 |
| 216 | 65,536 | 1 0000 0000 0000 0000 |
| 220 | 1,048,576 | 1 0000 0000 0000 0000 0000 |
| 224 | 16,777,216 | 1 0000 0000 0000 0000 0000 0000 |
| 231 | 2,147,483,648 | 1000 0000 0000 0000 0000 0000 0000 0000 |
| 232 | 4,294,967,296 | 1 0000 0000 0000 0000 0000 0000 0000 0000 |
8-bit two's complement
| Decimal | 8-bit pattern |
|---|---|
| 127 | 0111 1111 |
| 64 | 0100 0000 |
| 5 | 0000 0101 |
| 1 | 0000 0001 |
| 0 | 0000 0000 |
| −1 | 1111 1111 |
| −5 | 1111 1011 |
| −64 | 1100 0000 |
| −127 | 1000 0001 |
| −128 | 1000 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.