SuperDevTools

Binary calculator and hex calculator

Accepted prefixes: 0b (binary), 0o (octal), 0x (hex). Spaces and _ are ignored, a minus sign is allowed.

Operation

The result updates as you type. "Calculate" or the Enter key saves the calculation to the history.

Result

Working

History (last 10 calculations)

    No calculation saved yet.

    A binary calculator that shows its working

    This binary calculator runs operations on two numbers written in binary, octal, decimal or hexadecimal and gives the answer in all four bases at once. It is handy for checking binary addition homework in a GCSE or A level computer science course, building a bit mask for an embedded project, reading a hex register value or getting your head around two's complement. It also works as a hex calculator and a bitwise calculator.

    Everything is worked out in your browser, with exact whole numbers.

    How to use it

    1. Type the first number in "Number A" and pick its base under "Base of A". Do the same for "Number B". A 0b, 0o or 0x prefix selects the base for you.
    2. Click an operation: + − × ÷ (quotient and remainder), mod, power, AND, OR, XOR, NOT, NAND, NOR, or the shifts <<, >> and >>>. NOT only uses number A.
    3. Choose the "Word size": 8, 16, 32 or 64 bits, or "Unlimited" for integers of any length. Tick "Signed (two's complement)" to allow negative values.
    4. The result appears in the four bases, each with a "Copy" button. "Calculate" or the Enter key stores it in the "History (last 10 calculations)".

    Binary addition rules

    Binary addition works like column addition at school, right to left: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0 carry 1, and 1 + 1 + 1 = 1 carry 1. The "Working" section lines up the columns and writes the carries above them. Example: 1011 + 0110 = 10001, that is 11 + 6 = 17. The final carry becomes the leading digit of the answer.

    Two's complement and overflow

    With a fixed word size, a negative number is stored in two's complement: flip every bit of the positive value, then add 1. So −5 on 8 bits starts as 0000 0101, flips to 1111 1010, and adding 1 gives 11111011. Subtraction uses the same trick: A − B = A + (NOT B + 1). For 1011 − 0110 on 8 bits: 0000 1011 + 1111 1010 = 1 0000 0101; the carry that leaves the 8 bits is dropped, leaving 0000 0101, which is 5.

    A signed 8-bit number runs from −128 to 127. Working out 127 + 1 gives the pattern 1000 0000, shown as −128 under "Signed decimal" and 128 under "Unsigned decimal", and the tool flags an overflow. In "Unlimited" mode nothing ever overflows: 2 to the power 64 gives exactly 18,446,744,073,709,551,616.

    Bitwise operations

    AND sets a 1 where both bits are 1, OR where at least one is 1, XOR where they differ; NAND and NOR are their opposites. The "Bit-by-bit view" lines up A, B and the result, next to the "Truth table" for the operation. A classic mask: 0xFF AND 0x0F = 0x0F keeps only the four rightmost bits. NOT 0 on 16 bits gives 0xFFFF.

    Signed 8-bit calculationResult
    0000 0101 << 30010 1000 (40)
    1111 0000 >> 2 (copies the sign bit)1111 1100 (−4)
    1111 0000 >>> 2 (shifts in zeros)0011 1100 (60)
    1101 ÷ 11quotient 100, remainder 1

    Frequently asked questions

    What is the difference between the ÷ remainder and mod?

    The remainder of ÷ takes the sign of the dividend, mod takes the sign of the divisor. For −7 and 2: quotient −3, remainder −1, but −7 mod 2 = 1. With positive numbers both are the same.

    Why does 255 turn into −1?

    On 8 signed bits, the pattern 1111 1111 reads as −1. Untick "Signed (two's complement)" to read it as 255.

    What if a number is too big for the word size?

    Only the rightmost bits are kept, and a note under the number says so. Switch to "Unlimited" to keep the full value.

    What happens if I divide by zero?

    No result is shown; a message tells you that B is 0.