Binary calculator

Bit width
Operation

= 11 in decimal

= 6 in decimal

ResultExact
10001

Decimal
17
Hex
0x11

Working

Lined up digit by digit
101111+1106=1000117
    Guide

    How the binary calculator works

    1. Enter two binary numbers, A and B. Spaces, underscores, a 0b prefix and a minus sign are all fine.
    2. Choose an operation. NOT only uses A, and the shifts move A left or right by B places.
    3. Choose a width. Auto gives exact answers of any size. 8 to 64 bits wraps the result like a CPU register and flags carries and overflow.
    4. Read the result in binary, decimal and hex, with the working lined up underneath.

    Worked example

    Adding 1011 (11) and 110 (6). Work right to left like decimal addition, but carry when a column reaches 2: 1 + 1 is 10, so write 0 and carry 1.

    101111+1106=1000117

    1011 + 110 = 10001 (17)

    • Division gives a whole-number quotient and a remainder. 10111 ÷ 101 is 100, remainder 11.
    • In a fixed width, type negative numbers with a minus sign. They're stored as two's complement.
    • In a fixed width, right shifts are logical: zeros move in from the left.

    Bitwise truth table

    one bit at a time
    ABA AND BA OR BA XOR B
    00000
    01011
    10011
    11110
    Learn

    Binary arithmetic explained

    How computers add, subtract, multiply and divide in binary, and what bitwise operations are for.

    A binary calculator does arithmetic directly in base 2. This one adds, subtracts, multiplies and divides binary numbers, and also performs the bitwise operations programmers use every day: AND, OR, XOR, NOT and shifts. Results can be exact, at any size, or wrapped to a fixed 8, 16, 32 or 64-bit width like a real processor, with carries and overflow flagged. Here's how each operation works, so you can follow the working the calculator shows.

    Binary addition

    Binary addition follows the same column method as decimal, with simpler rules. 0 + 0 = 0, 0 + 1 = 1 and 1 + 1 = 10, which means write 0 and carry 1. With a carry coming in, 1 + 1 + 1 = 11, so you write 1 and carry 1. Add 1011 (11) and 110 (6) from right to left: 1 + 0 = 1, 1 + 1 = 0 carry 1, 0 + 1 + 1 = 0 carry 1, and 1 + 1 = 0 carry 1. The final carry becomes a new leftmost digit, giving 10001, which is 17.

    Binary subtraction

    Subtraction by hand also works column by column, borrowing when you need to take 1 from 0. 1011 − 110 gives 101, which is 11 − 6 = 5. Processors take a different route: they add the two's complement of the second number. In 8 bits, 6 is 00000110 and −6 is 11111010. Adding 00001011 + 11111010 gives 1 00000101, and dropping the carry leaves 00000101, or 5. Choose a fixed width in this binary calculator to see results stored that way. The two's complement calculator explains the negative patterns in more detail.

    Binary multiplication

    Multiplying in binary is easier than in decimal, because each digit of the multiplier is either 0 or 1. For every 1, write the other number shifted left by that position, then add the rows. For 101 × 11, the rows are 101 and 1010, and their sum is 1111. That's 5 × 3 = 15. This shift-and-add method is how simple processors multiply, and it's why multiplying by a power of two is just a shift.

    Binary division

    Binary long division works like decimal long division, except each step only asks whether the divisor fits, so every quotient digit is 0 or 1. 10111 ÷ 101 gives a quotient of 100 and a remainder of 11, which is 23 ÷ 5 = 4 remainder 3. This calculator always returns a whole-number quotient and the remainder, the same way integer division works in most programming languages. Dividing by zero shows an error.

    Bitwise operations: AND, OR, XOR and NOT

    Bitwise operations compare numbers one bit at a time, with no carrying. They're the basis of bit masks, flags and many fast algorithms:

    • AND gives 1 only where both bits are 1. It's used to test or clear bits: 11010110 AND 00001111 keeps just the low four bits, 00000110.
    • OR gives 1 where either bit is 1. It's used to set bits: 10000000 OR 00000001 gives 10000001.
    • XOR gives 1 where the bits differ. It's used to toggle bits: 11110000 XOR 10101010 gives 01011010. XOR with the same value twice returns the original number.
    • NOT flips every bit of a single number. In a fixed width, NOT x equals −x − 1 when read as a signed value.

    Shifts

    A left shift moves every bit toward the high end and fills in zeros on the right. Each place multiplies the value by 2, so 101 shifted left by 2 is 10100, or 5 × 4 = 20. A right shift moves the bits the other way, dividing by 2 for each place and dropping the remainder. In a fixed width, bits shifted past the edge are lost, and this binary calculator flags when that happens. Right shifts here are logical, filling the left with zeros. In Auto mode, a negative number shifted right rounds down, like an arithmetic shift.

    Fixed widths, carry and overflow

    Real processors work with registers of a fixed size. In 8-bit mode, the calculator keeps every input and result in 8 bits. A result that's too big for the unsigned range wraps around and is flagged as Carry out: 11111111 + 1 gives 00000000. A result outside the signed range is flagged as Signed overflow: 01111111 + 1 gives 10000000, which reads as −128. Seeing both flags side by side shows why the same addition can be correct as unsigned and wrong as signed.

    Getting reliable results

    • Use Auto for exact answers of any size, and a fixed width to imitate a specific data type.
    • Type negative numbers with a minus sign. Bitwise operations on negative numbers need a fixed width, because the answer depends on how many bits are used.
    • Use Use result as A to chain calculations, and Swap A and B to reverse an operation.
    • To read the result in other bases, try the binary to decimal converter or the binary to hex converter.

    To double-check a result, convert both inputs to decimal, do the sum there, and convert back. The binary to decimal converter makes that a few seconds' work.

    FAQ

    Frequently asked questions

    Quick answers about the binary calculator and how it works.

    How do I add binary numbers?

    Add column by column from the right, carrying like in decimal: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). 1011 + 110 is 10001, which is 11 + 6 = 17.

    How does binary subtraction work?

    Subtract column by column from the right, borrowing when you take 1 from 0, just as in decimal. 1011 − 110 is 101: 11 − 6 = 5. Results below zero get a minus sign in Auto mode, or wrap around as two's complement in a fixed width.

    What does division give?

    A whole-number quotient and a remainder. 10111 ÷ 101 gives 100 remainder 11, which is 23 ÷ 5 = 4 remainder 3. Dividing by zero shows an error.

    What's the difference between Auto and a fixed bit width?

    Auto gives exact answers of any size, with a minus sign for negative results. 8, 16, 32 and 64-bit modes work like a processor register: inputs and results are held in that many bits, results wrap around when they don't fit, and the signed and unsigned readings are both shown.

    What do Carry out and Signed overflow mean?

    In a fixed width, Carry out means the unsigned result didn't fit and wrapped around: 11111111 + 1 in 8 bits gives 00000000. Subtraction shows Borrow instead, and a left shift shows Bits shifted out.

    Signed overflow means the result is outside the signed range: 01111111 + 1 gives 10000000, which reads as −128 instead of 128.

    How do AND, OR, XOR and NOT work?

    They compare the numbers one bit at a time. AND gives 1 where both bits are 1, OR where either is, and XOR where exactly one is. 1100 and 1010 give 1000, 1110 and 0110. NOT flips every bit of A.

    In Auto mode, NOT flips the digits you typed. Pick a bit width to flip a fixed number of bits.

    What do the shift operations do?

    << moves the bits of A left by B places, which multiplies by 2 for each place: 101 << 10 is 10100, or 5 × 4 = 20. >> moves them right, dividing by 2 for each place and dropping the remainder.

    B is the number of places, written in binary. In a fixed width, bits shifted past the edge are lost.

    Can I use negative numbers?

    Yes. Type a minus sign, like -101. Arithmetic works in every mode. AND, OR, XOR and NOT need a fixed width for negative numbers, because the result depends on how many bits are used. In a fixed width, negative inputs are stored as two's complement.

    Still have a question?Contact us