Skip to content

Binary Calculator

Add, subtract, multiply and divide binary or hex numbers, run bitwise AND, OR, XOR, NOT and shifts, and see two's complement at 8 to 64 bits with decimal.

Calculator Details

Result (binary):1 0001See results ↓

Arithmetic (+ − × ÷) or a bitwise operation on the two’s-complement bit patterns

Binary (0s and 1s) or hexadecimal (0–9 and A–F) for A and B; results are shown in both

Register size for two’s complement, bitwise operations and overflow checks

e.g. 1011 in binary or 1F in hex; start with - for a negative number

Not used by NOT and the shifts

Your Results

Result (binary): 1 0001

Result (binary)

1 0001

  • Decimal

    17

  • Hexadecimal

    11

  • 8-bit pattern

    0001 0001

    Signed 17, unsigned 17

Fits in 8 bits as signed and unsignedTwo's complement pattern 00010001 (hex 11).

Step by step

carry111
A1011= 11
+ B110= 6
=10001

In other bases

Operands and result in binary, decimal, hexadecimal and as 8-bit patterns
 DecimalHex8-bit two's complement
A11B0000 1011
B660000 0110
Result17110001 0001

The result is 10001 in binary, which is 17 in decimal and 11 in hex; as a two's-complement pattern at 8 bits it is 00010001 (signed 17).

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

How This Calculator Works

How it's calculated

Each binary digit is a power of 2: 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 11. Arithmetic is done exactly on the signed values (division truncates toward zero). Bitwise operations work position by position on the 8-bit two's-complement patterns, where a negative number −x is stored as 2^8 − x (invert the bits and add 1).

With your numbers

A = 1011₂ = 11
B = 110₂ = 6
11 + 6 = 17 = 10001₂
8-bit pattern 00010001 = 17 unsigned = 17 signed = 0x11

Frequently Asked Questions

How do you add binary numbers?

Line the numbers up on the right and add column by column, like decimal addition: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). For 1011 + 110: the result is 10001, which is 11 + 6 = 17. The steps table shows the carries for your numbers.

How do you subtract binary numbers?

Either borrow column by column (10 − 1 = 1), or add the two’s complement of the number being subtracted, which is how computers do it. 101 − 1100 is 5 − 12 = −7, written −111. In 8 bits, −7 is stored as 11111001.

What is two’s complement?

The standard way computers store negative integers. In w bits, a negative number −x is stored as 2^w − x, which is the same as inverting every bit of x and adding 1. The top bit then works as a sign bit: 8-bit patterns from 00000000 to 01111111 are 0 to 127, and 10000000 to 11111111 are −128 to −1. Adding patterns with ordinary binary addition then gives the right signed answer.

What is overflow?

A result that doesn’t fit in the chosen number of bits. In 8 bits, signed values run from −128 to 127 and unsigned from 0 to 255. 127 + 1 = 128 overflows as signed: the stored pattern 10000000 reads as −128. The calculator shows the exact result, the wrapped pattern a w-bit register would hold, and whether it fits as signed or unsigned.

How does binary division work here?

The quotient is truncated toward zero and the remainder has the same sign as the dividend, as in C, Java, JavaScript BigInt and most processors. 11011 ÷ 101 (27 ÷ 5) gives 101 remainder 10 (5 remainder 2); −11011 ÷ 101 gives −101 remainder −10.

What do AND, OR, XOR and NOT do?

They work on each bit position separately. AND gives 1 only where both bits are 1, OR where either is 1, XOR where exactly one is 1, and NOT flips every bit. 11001100 AND 10101010 = 10001000, OR = 11101110, XOR = 01100110. They are used for masks, flags and permissions.

What is the difference between logical and arithmetic right shift?

Both move the bits right and drop the lowest ones. A logical shift fills the top with 0s, so it suits unsigned numbers: 10000000 >>> 2 = 00100000 (128 → 32). An arithmetic shift copies the sign bit, so it divides signed numbers by 2ⁿ (rounding down): 10000000 >> 2 = 11100000 (−128 → −32). A left shift multiplies by 2ⁿ, dropping bits past the width.

How large can the numbers be?

Arithmetic is exact for numbers up to 128 binary digits each (about 3.4 × 10³⁸), using arbitrary-precision integers, so there is no rounding. Bitwise operations and the two’s-complement pattern use the bit width you choose: 8, 16, 32 or 64 bits.

Exact integer arithmetic on binary numbers of up to 128 digits (or hex numbers of up to 32 digits), with division truncated toward zero; bitwise operations and two's-complement patterns at 8, 16, 32 or 64 bits. Not included: binary fractions, floating point (IEEE 754) and rotations.

Binary Calculator: Binary Arithmetic, Bitwise Operations and Two's Complement

By FindMySum · Last reviewed

A binary calculator does arithmetic directly in base 2, the number system every digital computer uses. This one adds, subtracts, multiplies and divides binary numbers of up to 128 digits exactly, runs the bitwise operations programmers use every day (AND, OR, XOR, NOT and shifts), and shows each result in decimal and hexadecimal and as a two's-complement bit pattern at 8, 16, 32 or 64 bits, with a warning when the result overflows that width. A step-by-step table lines the bits up the way you would on paper.

Binary in one paragraph

Each binary digit (bit) is worth a power of 2, doubling from the right: 1, 2, 4, 8, 16 and so on. So 1011 is 8 + 0 + 2 + 1 = 11, and 110 is 4 + 2 + 0 = 6. Hexadecimal groups bits in fours (0000 = 0 up to 1111 = F), which is why programmers write 8-bit values as two hex digits.

Binary arithmetic

Addition works like decimal addition with only two digits. The rules are 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1).

The calculator's default is 1011 + 110:

carry    111
          1011
    +      110
    =    10001

Reading right to left: 1 + 0 = 1; 1 + 1 = 0 carry 1; 0 + 1 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; and the last carry becomes the leading 1. The answer 10001 is 16 + 1 = 17, and 11 + 6 = 17 confirms it. Hexadecimal: 0x11.

Subtraction can be done by borrowing (10 − 1 = 1 in a column), but computers add the two's complement instead (see below). If the second number is larger, the answer is negative: 101 − 1100 is 5 − 12 = −111 (−7).

Multiplication is shift-and-add: for every 1 in the second number, add a copy of the first number shifted left by that position. 1101 × 101 = 1101 + 110100 = 1000001 (13 × 5 = 65).

Division gives a quotient and a remainder. 11011 ÷ 101 is 27 ÷ 5 = 101 remainder 10 (5 remainder 2). With negative numbers the calculator follows the rule used by C, Java, JavaScript and most processors: the quotient is truncated toward zero and the remainder has the sign of the dividend, so −27 ÷ 5 gives −5 remainder −2.

Two's complement: how negative numbers are stored

A register has a fixed number of bits, and there is no separate place for a minus sign. Two's complement solves this: in w bits, a negative number −x is stored as the pattern for 2^w − x. A quick way to find it is to invert every bit and add 1:

  • 7 in 8 bits is 00000111.
  • Invert: 11111000.
  • Add 1: 11111001, which is how −7 is stored. (Check: 256 − 7 = 249 = 11111001.)

The top bit acts as the sign: patterns starting with 0 are 0 to 127, patterns starting with 1 are −128 to −1. The big advantage is that ordinary binary addition gives the right answer for signed numbers too, so the same circuit adds signed and unsigned values.

The calculator shows every result's pattern at the bit width you choose, and reads that pattern both ways: as an unsigned number and as a signed (two's complement) number.

Overflow

Every bit width has limits. In 8 bits, unsigned values run from 0 to 255 and signed values from −128 to 127. A result outside the range overflows: the register keeps only the lowest 8 bits. For example, 1111111 + 1 is 127 + 1 = 128. That is fine as an unsigned 8-bit value, but as a signed value the pattern 10000000 means −128: adding two positive numbers produced a negative one. The calculator gives the exact result, the pattern an 8-bit register would actually hold, and whether the result fits as signed, unsigned, both or neither.

Bitwise operations

Bitwise operations work on each bit position independently, on the fixed-width patterns:

OperationRule per bit11001100 with 10101010
AND1 if both bits are 110001000
OR1 if either bit is 111101110
XOR1 if exactly one bit is 101100110
NOT (of the first)flip the bit00110011

Shifts slide the whole pattern:

  • Left shift by n moves bits toward the high end and fills with 0s, multiplying by 2ⁿ; bits pushed past the width are lost. 11000001 << 2 in 8 bits is 00000100.
  • Logical right shift moves bits toward the low end and fills with 0s: 10000000 >>> 2 = 00100000 (128 → 32).
  • Arithmetic right shift fills with copies of the sign bit, which divides a signed number by 2ⁿ, rounding down: 10000000 >> 2 = 11100000 (−128 → −32).

Operands for bitwise operations must fit in the chosen width (as signed or unsigned); if one doesn't, pick a wider width.

Hexadecimal arithmetic

Hexadecimal (base 16) is binary written four bits at a time: each hex digit 0–9 or A–F stands for one group of four bits, so 1111 0000 is F0 and a byte is always two hex digits. That makes it the usual way to write memory addresses, colours and machine words, and it is why the calculator can do hex arithmetic as well. Choose hexadecimal under "Numbers typed in" and the inputs are read as hex; the operations are the same, and the result is shown in hex first, then binary and decimal.

The rules mirror decimal arithmetic with a carry at 16 instead of 10. Adding 1F and A: F + A is 15 + 10 = 25, which is 1 sixteen and 9 left over, so write 9 and carry 1; then 1 + 1 = 2, giving 29 (41 in decimal). DEADBEEF + 1 carries once, to DEADBEF0. Multiplying 1A by 2B gives 45E (26 × 43 = 1,118), and FF ÷ 10 gives F with a remainder of F (255 ÷ 16 = 15 remainder 15). Bitwise operations are easiest to see in hex: F0 AND 3C keeps only the bits set in both, 30. Up to 32 hex digits are accepted, the same 128 bits as the binary input.

Limits

The calculator handles whole numbers only. It doesn't do binary fractions (such as 101.11), IEEE 754 floating-point formats or bit rotations. Arithmetic is exact for inputs up to 128 binary digits; bit patterns are shown for 8, 16, 32 and 64 bits.

More questions

Why do computers use binary?

Because each digit only needs two states, on or off, which transistors represent reliably and cheaply. Every number, character and instruction in a computer is ultimately a pattern of bits. Hexadecimal is used as shorthand because each hex digit stands for exactly four bits: 1111 1001 is F9.

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

Write the powers of 2 under the digits from the right (1, 2, 4, 8, 16, …) and add the powers where the digit is 1. For 10001: 16 + 1 = 17. To go the other way, divide by 2 repeatedly and read the remainders from the bottom up. The number system converter does this for any base from 2 to 36.

Can I add or multiply hexadecimal numbers?

Yes. Set "Numbers typed in" to hexadecimal and type A and B with the digits 0–9 and A–F (a 0x prefix is fine). Every operation, from addition and division to AND, OR and the shifts, then runs on their values, and the result is shown in hex, binary and decimal. For example 1F + A = 29 in hex, which is 41 in decimal.

What is the range of an n-bit number?

Unsigned, 0 to 2ⁿ − 1: 255 for 8 bits, 65,535 for 16, about 4.29 billion for 32 and about 1.8 × 10¹⁹ for 64. Signed two's complement, −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: −128 to 127 for 8 bits, −32,768 to 32,767 for 16, about ±2.15 billion for 32 and about ±9.2 × 10¹⁸ for 64.

What is sign extension?

Copying the sign bit into the new high bits when a two's-complement number is widened, so its value doesn't change. −7 is 11111001 in 8 bits and 1111111111111001 in 16 bits. Positive numbers are padded with 0s. Switch the bit width in the calculator to see the pattern of the same value at 8, 16, 32 and 64 bits.

What are bitwise operations used for in practice?

Masks and flags: AND with a mask keeps selected bits (a subnet mask ANDed with an IP address gives the network address), OR sets bits, XOR toggles bits and is used in checksums and simple ciphers, and shifts multiply or divide by powers of two quickly. File permissions such as 755 on Linux are three groups of three permission bits.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy