Binary Calculator

Add, subtract, multiply and divide binary numbers, use bitwise AND, OR and XOR, and convert between binary and decimal, with the working shown.

Binary calculator
Calculate
Result

    Working

    Works with whole numbers of any length using exact arithmetic. Negative numbers can be entered with a minus sign. Division gives the whole-number quotient and the remainder. AND, OR and XOR compare the bits of non-negative numbers.

    On this page

    A binary calculator adds, subtracts, multiplies and divides binary numbers, performs bitwise AND, OR and XOR, and converts between binary and decimal, showing the working for each step. It handles whole numbers of any length with exact arithmetic and also shows every result in hexadecimal and octal.

    For example, 1011 + 110 = 10001 in binary, which is 11 + 6 = 17 in decimal. 101 × 11 = 1111 (5 × 3 = 15). The binary number 101101 equals 45 in decimal, and 255 in decimal is 11111111 in binary.

    How to use the binary calculator

    1. Choose binary arithmetic, binary to decimal, or decimal to binary.
    2. Enter binary numbers using only 0s and 1s. You can include spaces or a 0b prefix; they’re ignored. Add a minus sign for negative numbers.
    3. For arithmetic, choose the operation: add, subtract, multiply, divide, AND, OR or XOR.
    4. Press Calculate to see the result in binary, decimal, hexadecimal and octal, with the working.

    What is binary?

    Binary is a base-2 number system that uses only two digits, 0 and 1. Each position is worth twice the one to its right: 1, 2, 4, 8, 16, 32 and so on, just as each position in decimal is worth ten times the one to its right. Computers use binary because their circuits have two states, off and on, which map naturally to 0 and 1. Each binary digit is called a bit, and 8 bits make a byte.

    Converting binary to decimal

    Multiply each digit by its place value, a power of 2, and add up the results. For 101101:

    Digit101101
    Place value32168421

    32 + 8 + 4 + 1 = 45. Only the positions with a 1 count.

    Converting decimal to binary

    Divide the number by 2 repeatedly and write down each remainder. Then read the remainders from the last one to the first. For 45:

    • 45 ÷ 2 = 22 remainder 1
    • 22 ÷ 2 = 11 remainder 0
    • 11 ÷ 2 = 5 remainder 1
    • 5 ÷ 2 = 2 remainder 1
    • 2 ÷ 2 = 1 remainder 0
    • 1 ÷ 2 = 0 remainder 1

    Reading from bottom to top gives 101101.

    Binary arithmetic

    Addition

    Binary addition follows four simple rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10, which means write 0 and carry 1. Also, 1 + 1 + 1 = 11: write 1 and carry 1. Adding 1011 and 110 column by column from the right gives 10001.

    Subtraction

    The rules are 0 − 0 = 0, 1 − 0 = 1, 1 − 1 = 0, and 0 − 1 = 1 with a borrow from the next column. 1011 − 110 = 101, which is 11 − 6 = 5. Computers usually subtract by adding the two’s complement of the second number, which lets the same circuit handle addition and subtraction.

    Multiplication

    Binary multiplication is like long multiplication in decimal, but simpler: each row is either a copy of the first number (when the digit is 1) or all zeros (when it’s 0), shifted left one place per row. 101 × 11 = 101 + 1010 = 1111.

    Division

    Binary long division works like decimal long division. 1101 ÷ 11 is 13 ÷ 3, which is 4 remainder 1, or 100 remainder 1 in binary. The calculator shows both the quotient and the remainder.

    Bitwise operations

    Bitwise operations compare two numbers bit by bit, and they’re widely used in programming, networking and digital electronics.

    • AND: the result bit is 1 only if both bits are 1. 1100 AND 1010 = 1000. Used to mask or extract certain bits, such as checking whether a flag is set.
    • OR: the result bit is 1 if either bit is 1. 1100 OR 1010 = 1110. Used to switch bits on.
    • XOR: the result bit is 1 if the bits are different. 1100 XOR 1010 = 0110. Used for toggling bits, simple encryption and error detection.

    Binary, hexadecimal and octal

    Long binary numbers are hard to read, so programmers often use hexadecimal (base 16) or octal (base 8). Each hexadecimal digit stands for exactly four bits, and each octal digit for three. 1111 1111 in binary is FF in hexadecimal and 377 in octal, all equal to 255. The calculator groups binary results into blocks of four to make the link with hexadecimal easy to see.

    DecimalBinaryHexadecimal
    000000
    501015
    910019
    101010A
    151111F
    161 000010
    2551111 1111FF

    Counting in binary

    Counting in binary works just like counting in decimal, except you run out of digits after 1. The sequence goes 0, 1, 10, 11, 100, 101, 110, 111, 1000, and so on. Each time every digit is 1, the next number adds a new place on the left, just as 999 is followed by 1000 in decimal. With n bits you can count from 0 to 2ⁿ − 1: 4 bits reach 15, 8 bits reach 255 and 16 bits reach 65,535.

    Negative numbers and two’s complement

    This calculator shows negative results with a minus sign, such as −101 for −5. Inside a computer, negative numbers are usually stored using two’s complement. To find the 8-bit two’s complement of 5 (0000 0101), flip every bit to get 1111 1010, then add 1 to get 1111 1011, which represents −5. The advantage is that the computer can subtract by simply adding: 0000 1011 (11) + 1111 1011 (−5) = 0000 0110 (6), ignoring the carry out of the top bit.

    Binary fractions

    Binary can represent fractions too, using places to the right of a binary point worth ½, ¼, ⅛ and so on. 0.101 in binary is ½ + ⅛ = 0.625. Some simple decimals, such as 0.1, can’t be written exactly in binary and repeat forever, which is why computers sometimes show tiny rounding errors such as 0.1 + 0.2 = 0.30000000000000004. This calculator works with whole numbers to keep every result exact.

    Binary and storage sizes

    Because computers work in binary, memory sizes come in powers of 2. A kibibyte (KiB) is 2¹⁰ = 1,024 bytes, a mebibyte (MiB) is 2²⁰ = 1,048,576 bytes and a gibibyte (GiB) is 2³⁰ = 1,073,741,824 bytes. Storage manufacturers usually use decimal units instead, where a gigabyte is 1,000,000,000 bytes, which is why a “500 GB” drive shows as about 465 GiB on many computers.

    Tips for working with binary

    • Learn the powers of 2 up to 2¹⁰ = 1,024; they make conversions much quicker.
    • Group long binary numbers into blocks of four bits from the right to read them more easily and convert them to hexadecimal.
    • Check your answer by converting both numbers and the result to decimal.
    • Leading zeros don’t change a binary number’s value: 0101 and 101 are both 5.

    Where binary is used

    • Computers and phones: all data, from text to photos, is stored as bits.
    • Networking: IP addresses and subnet masks are binary numbers written in decimal form.
    • Colours: each colour channel on a screen is usually 8 bits, from 0 to 255.
    • Digital electronics: logic gates implement AND, OR and XOR in hardware.
    • Computer science courses: binary arithmetic is a core topic.

    Related calculations

    For related questions, use the hex calculator to do hexadecimal arithmetic and convert hex to decimal, or the scientific notation calculator to convert numbers to and from scientific notation.

    Frequently asked questions

    Multiply each digit by its place value (1, 2, 4, 8, …) from the right and add the results. 101101 = 32 + 8 + 4 + 1 = 45.

    Divide by 2 repeatedly, note each remainder, then read the remainders from last to first. 45 becomes 101101.

    Add column by column from the right: 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 10 (write 0, carry 1). 1011 + 110 = 10001.

    11111111, which is eight 1s in a row. It's the largest number that fits in one byte, and FF in hexadecimal.

    A bit is a single binary digit, 0 or 1. A byte is 8 bits and can represent 256 different values, from 0 to 255.

    It gives 1 where the two bits differ and 0 where they're the same. 1100 XOR 1010 = 0110.

    Usually by adding the two's complement of the second number, which is found by inverting its bits and adding 1.

    Yes. The calculator uses exact whole-number arithmetic, so long binary numbers are handled without any rounding, however many digits they have.

    255, written 11111111. With n bits, the largest unsigned value is 2ⁿ − 1.

    0, 1, 10, 11, 100, 101, 110, 111, 1000. When every digit is 1, the next number adds a new place on the left.

    A way to store negative numbers: flip every bit of the positive number and add 1. In 8 bits, −5 is 11111011.

    No. 0101 and 101 both equal 5. Leading zeros are often added to fill a fixed number of bits.

    Each hexadecimal digit represents exactly four bits, so long binary numbers can be written much more compactly.