FLXCode Binary Calculator

FLXCode apps

Appearance

Binary Calculator

Do arithmetic in binary. Type zeros and ones, press an operation and read the answer in binary, with the same value in hex and decimal next to it.

Type with the keyboard or the keys below, or paste a number. Click a row to type in that base.

Bits (click one to flip it)

Try an example

History (this visit only)

    Nothing yet. Results appear here, newest first.

    Keyboard shortcuts
    0–9, A–Ftype digits (digits outside the input base are refused)
    + − * / %add, subtract, multiply, divide, modulo
    & | ^ ~AND, OR, XOR, NOT
    q wNAND, NOR
    < > sshift left, shift right (logical), shift right (arithmetic)
    r Shift+Rrotate left, rotate right
    nchange sign
    Enter or =equals (ENTER in RPN mode)
    Backspacedelete the last digit
    Escclear the number; press again to clear everything
    x k DeleteRPN: swap X and Y, roll the stack down, drop X

    No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.

    Problem or idea? Email us

    Quick start

    1. BIN is the input row, so only the keys 0 and 1 are on. Type the first number.
    2. Press +, −, × or ÷, type the second number and press =.
    3. The bit grid shows the answer bit by bit. A flag line appears when a carry or borrow went past the top bit.

    Worked examples

    SumWordBinary resultDecimal resultFlagWhy
    1011 + 1108-bit unsigned0001 000117none11 + 6 = 17.
    1111 1111 + 18-bit unsigned0000 00000carryEvery bit is one, so the carry runs the whole way and falls off the end.
    101 − 1118-bit unsigned1111 1110254carry5 − 7 needs a borrow past the top bit. The byte holds 254, which is also -2 read as signed.
    1010 − 118-bit unsigned0000 01117none10 − 3 = 7.
    1101 × 118-bit unsigned0010 011139none13 × 3 = 39.
    1111 × 11118-bit unsigned1110 0001225none15 × 15 = 225, which still fits eight bits.
    1101 ÷ 108-bit unsigned0000 01106, remainder 1none13 ÷ 2 = 6 remainder 1.
    0111 1111 + 18-bit signed1000 0000-128overflowSigned: 127 + 1 does not fit, so it overflows to -128.

    Carry: adding one column

    Each column adds two bits and a carry that came from the right. The total is at most 3, which is 11 in binary: a bit to write and a bit to carry.

    Top bitBottom bitCarry inWriteCarry out
    00000
    01010
    10010
    11001
    11111

    Adding by hand

    1011 + 0110, from the right.

    ColumnTopBottomCarry inTotalWriteCarry out
    1100110
    2110201
    3011201
    4101201

    The last carry out is a fifth bit, so the answer is 10001, which is 17.

    Borrow: subtracting one column

    1010 − 0011. A column with a 0 on top and a 1 below borrows from the left. The borrowed 1 is worth 2 here, so 0 becomes 2 before you subtract.

    ColumnTopBorrowed inTop afterBottomWriteBorrow out
    1002111
    2112111
    3011011
    4110000

    The answer is 0111, which is 7. If the last borrow out were 1, the first number was smaller and the result would wrap.

    Multiplying and dividing

    Multiplying by a power of two is a shift: 1101 × 100 is 110100. A general product is a sum of shifted copies, one for each 1 in the bottom number. Dividing by a power of two is a shift to the right, and the bits that drop off are the remainder.

    If a product needs more bits than the word has, the high bits are cut and the carry flag is set. Use 16, 32 or 64 bits for larger products.

    Negative numbers

    In signed mode the top bit is the sign, and negative numbers are stored in two's complement: flip every bit and add one. 0000 0101 is 5, so -5 is 1111 1011. The +/− key does this for you, and the DEC row shows the value you meant.

    Numbers this uses

    • Digits 0 and 1 in the BIN row. Spaces and underscores in a pasted number are ignored.
    • Word sizes 8, 16, 32 and 64 bits, exact integers (BigInt). This page starts at 8.
    • Division is integer division that rounds toward zero, with the remainder shown.

    To convert only, use binary to decimal or binary to hex. For AND, OR, XOR and shifts see the bitwise calculator, or open the programmer calculator for everything.

    Nothing you type is uploaded. We count events without cookies (details).

    FAQ

    How do I add binary numbers?

    Add column by column from the right. 0 + 0 is 0, 0 + 1 is 1, and 1 + 1 is 10, so you write 0 and carry 1. With a carry coming in, 1 + 1 + 1 is 11, so you write 1 and carry 1. The column table above works through 1011 + 0110.

    How do I subtract binary numbers?

    Subtract column by column. If the top bit is 0 and the bottom bit is 1, borrow from the next column to the left. The borrowed 1 is worth 2 in the column you are working on. If there is nothing left to borrow from, the result goes below zero and the calculator wraps it, with borrow shown as carry.

    What does the carry flag mean here?

    In unsigned mode it means the exact answer did not fit in the word. For an addition that is a carry out of the top bit. For a subtraction it is a borrow: the first number was smaller than the second. The result left on screen is the exact answer modulo 2 to the power of the word size.

    How does binary multiplication work?

    Each 1 in the bottom number adds a copy of the top number, shifted left by that bit's position. 1101 × 11 is 1101 shifted by 0 plus 1101 shifted by 1: 1101 + 11010 = 100111, which is 39. There is no times table because the only digits are 0 and 1.

    How does binary division work?

    Long division, with a simple rule at each step: the next quotient bit is 1 if the divisor fits into what you have, else 0. The tool gives the whole-number quotient and the remainder. 1101 ÷ 10 is 110 remainder 1, which is 13 ÷ 2 = 6 remainder 1.

    Can I use negative binary numbers?

    Yes, switch to signed. The top bit then means negative: 1111 1110 is -2 in 8 bits. Type the bit pattern in the BIN row, or click DEC, type the decimal digits, press +/− and read the pattern in the BIN row. Choose the word size first, because the pattern depends on it.

    How many bits do I get?

    Pick 8, 16, 32 or 64. This page starts with 8 so a whole number fits on screen. The bit grid below the value shows every bit, and you can click one to flip it.

    Is anything I type saved or sent?

    No. Everything runs in your browser. What you type is not put in the address bar, not stored and not counted. Only your last word size and input base are remembered on this device.

    More from FLXCode

    Share Binary Calculator