Binary Calculator: Add, Subtract, Convert Base 2

Add, subtract, multiply and divide binary numbers, convert to decimal, and apply bitwise operations. The Binary Calculator shows place values and two's complement.

01 calculator

Results update as you type. Ctrl/Cmd+Enter copies the primary result.

Result

    Show the working

      The Binary Calculator adds, subtracts, multiplies and divides numbers written in base 2, converts between binary and decimal, and applies bitwise AND, OR, XOR, NOT and shifts. Every result includes the decimal equivalent and a column breakdown so carries and borrows can be checked by hand. Bit width can be set for two's complement work, or left unbounded for exact arithmetic with no register wrap.

      All calculation runs in your browser. Nothing you enter is sent to a server.

      Add, subtract, multiply and divide binary numbers

      Concept diagram: Inputs leads to Add, subtract, multiply and divide… leads to ResultInputsAdd, subtract, multiplyand divide…Result
      Add, subtract, multiply and divide binary numbers.

      Binary arithmetic uses the same column rules as decimal, but each place holds only 0 or 1 and the carry threshold is 2 instead of 10. Enter two binary strings, choose the operation, and the calculator returns the result in binary with the decimal check beside it. Leading zeros are stripped from the output unless a bit width is selected.

      Addition carries when a column sums to 2 or more. Subtraction borrows from the next higher bit when the minuend digit is smaller. Multiplication and division follow the same long-form patterns taught for decimal, built from shifts and adds. Invalid digits such as 2 or A are rejected immediately, because they are not legal in base 2.

      Convert binary to decimal

      Scale bar: 1 binary equals 1.43 decimal1 binary1.43 decimal
      Convert binary to decimal.

      Positional notation turns a binary string into a decimal integer by summing each bit multiplied by its power of two. The rightmost bit is 2⁰ (value 1), the next is 2¹ (value 2), then 4, 8, 16, and so on. Enter 10111 and the expansion is 16 + 0 + 4 + 2 + 1 = 23.

      1 0 1 1 1
      │ │ │ │ └─ 1 × 2⁰ = 1
      │ │ │ └─── 1 × 2¹ = 2
      │ │ └───── 1 × 2² = 4
      │ └─────── 0 × 2³ = 0
      └───────── 1 × 2⁴ = 16
                         = 23

      Any binary string the calculator accepts converts this way. Grouping into nibbles of four bits makes the places easier to read aloud: 1010 1010 is clearer than eight unbroken digits when checking a subnet mask or a permission bitfield.

      Convert decimal to binary

      Scale bar: 1 decimal equals 1.4 binary1 decimal1.4 binary
      Convert decimal to binary.

      Repeated division by 2 produces binary digits as remainders. Divide the decimal value by 2, record the remainder (0 or 1), divide the quotient again, and continue until the quotient is zero. Reading the remainders from last to first yields the binary form.

      For 23:

      StepQuotientRemainder
      23 ÷ 2111
      11 ÷ 251
      5 ÷ 221
      2 ÷ 210
      1 ÷ 201

      Reading remainders upward gives 10111. The calculator performs this conversion in either direction and shows both forms together so a mistyped digit is obvious before the arithmetic step.

      Add 10101010 and 11001100

      Concept diagram: Inputs leads to Add 10101010 and 11001100 leads to ResultInputsAdd 10101010 and11001100Result
      Add 10101010 and 11001100.

      Adding 10101010 and 11001100 is the worked fixture for column addition with carries. In decimal the operands are 170 and 204, and the sum is 374, which is 101110110 in binary. Older outline notes that listed 110001110 were wrong; the arithmetic below is the correct result.

      1 1 1 1 1 0 0 0     carries
                  1 0 1 0 1 0 1 0   170
                + 1 1 0 0 1 1 0 0   204
                -----------------
                1 0 1 1 1 0 1 1 0   374

      Column by column from the right: 0+0=0, 1+0=1, 0+1=1, 1+1=0 carry 1, 0+0+carry=1, 1+0=1, 0+1=1, 1+1=0 carry 1, and the final carry writes a ninth bit. The nine-bit result 101110110 matches 256 + 0 + 64 + 32 + 16 + 0 + 4 + 2 + 0 = 374. The Binary Calculator shows this carry row for every addition so the hand check lines up with the output.

      Subtract binary numbers with borrowing

      Concept diagram: Inputs leads to Subtract binary numbers with… leads to ResultInputsSubtract binary numberswith…Result
      Subtract binary numbers with borrowing.

      Binary subtraction borrows when a column needs to take 1 from a 0. Borrowing from the next higher bit turns the current 0 into 2 (binary 10), and the lender loses 1. If that lender is also 0, the borrow propagates until it finds a 1.

      Example: 1000 minus 0001.

      1 0 0 0
      - 0 0 0 1
      ---------
        0 1 1 1

      The rightmost column borrows across three zeros. After the chain settles, each borrowed column becomes 1, and the leftmost bit that lent becomes 0, leaving 0111 (decimal 7). When a bit width is set and the result would go negative, the calculator can show the two's complement wrap instead of an unbounded negative magnitude. Unbounded mode keeps the signed integer exact without wrapping.

      Apply bitwise operations

      Concept diagram: Inputs leads to bitwise operations leads to ResultInputsbitwise operationsResult
      Apply bitwise operations.

      Bitwise operators act on each bit independently rather than on the string as one integer. AND returns 1 only where both inputs are 1. OR returns 1 where either input is 1. XOR returns 1 where bits differ. NOT flips every bit in the selected width. Shifts move bits and fill zeros, or the sign bit for arithmetic right shift.

      ABANDORXOR
      00000
      01011
      10011
      11110

      A bit mask clears or keeps selected fields. value AND mask zeros every bit where the mask is 0. value OR flag sets bits. value XOR toggle flips selected bits without disturbing the rest. These patterns appear in permission flags, status registers, and the network portion of an IPv4 address when a subnet mask is applied.

      Represent negative numbers in two's complement

      Concept diagram: Inputs leads to Represent negative numbers in two's… leads to ResultInputsRepresent negativenumbers in two's…Result
      Represent negative numbers in two's complement.

      Two's complement is the standard way fixed-width binary stores negative integers. For an n-bit register, negate a value by inverting every bit and adding one. The high bit is the sign bit: 0 for non-negative, 1 for negative. The representable range for n bits is −2ⁿ⁻¹ through 2ⁿ⁻¹ − 1.

      In 8 bits, +5 is 00000101. Invert to 11111010, add one to get 11111011, which is −5. Adding 00000101 and 11111011 yields 00000000 with an overflow carry out of the register, which is how negation checks out. Without a width, there is no fixed sign bit and two's complement is undefined; the calculator therefore requires a width (8, 16, 32 or 64) before showing complement forms.

      Overflow happens when the true mathematical result does not fit the chosen width. The Binary Calculator flags wrap so a silently truncated answer is not mistaken for an exact one.

      Read the binary place value table

      Number line from 0 to 100 with the value 39 marked025507510039
      Read the binary place value table.

      Place values double at every step left of the binary point. Memorising the first eight is enough for most byte-level work: 1, 2, 4, 8, 16, 32, 64, 128. Four bits make a nibble; eight bits make a byte. Sixteen bits make a word on many architectures; 32 and 64 are the common register sizes today.

      Bit indexPowerValue
      02⁰1
      12
      24
      38
      42⁴16
      52⁵32
      62⁶64
      72⁷128

      A full byte of ones, 11111111, is 255. The high bit alone, 10000000, is 128. Reading a value as the sum of its set place values is faster than converting digit by digit once the table is familiar, and the calculator's expansion view matches that mental check.

      Use binary in practice

      Concept diagram: Inputs leads to binary in practice leads to ResultInputsbinary in practiceResult
      Use binary in practice.

      Binary shows up wherever hardware or protocols expose bitfields. Subnet masks are 32-bit patterns of leading ones. Unix file modes pack read, write and execute bits into nine permission bits. Colour channels are often eight-bit values. CPU flags and device registers pack boolean state into single bits so a mask can test or clear them without touching neighbours.

      Memory addresses and machine instructions are binary underneath every hex dump. When debugging, converting a suspicious flag word to binary and lining it up against the datasheet is usually faster than guessing from the decimal form. The calculator keeps the binary and decimal views linked so that round trip stays honest.

      Frequently asked questions

      How does binary addition produce a carry?

      A carry appears when a column sums to 2 or more. Because each place can store only 0 or 1, a sum of 2 writes 0 and carries 1 to the next column; a sum of 3 writes 1 and carries 1. The process is identical to decimal carrying at 10, with a smaller threshold.

      How do you convert binary to decimal by hand?

      Multiply each bit by its power of two and add the products. The rightmost bit is worth 1, then 2, 4, 8, and so on. For 10111 that is 16 + 0 + 4 + 2 + 1 = 23. The calculator shows the same expansion for every conversion.

      How do you convert decimal to binary by hand?

      Divide the number by 2 repeatedly and collect remainders. Each remainder is the next binary digit from right to left. Stop when the quotient reaches zero, then read the remainders from last to first. Decimal 23 becomes 10111 by that method.

      What is two's complement?

      Two's complement represents negative integers in a fixed bit width by inverting the bits of the magnitude and adding one. The high bit acts as the sign. Adding a number to its two's complement yields zero within that width, which is why processors use it for subtraction.

      What is a bit mask?

      A bit mask is a binary pattern used with AND, OR or XOR to clear, set or toggle selected bits. ANDing with a mask keeps bits where the mask is 1 and zeros the rest. ORing sets bits. XORing flips them. Masks appear in permissions, protocol flags and hardware registers.

      What is the difference between a left shift and multiplying by two?

      A left shift by one place multiplies an unsigned value by two, provided no bits shift out of the register. A right shift by one divides by two and discards the remainder. With a fixed width, bits that shift off the end are lost; unbounded mode grows the string instead.

      Why does bit width matter for NOT and negation?

      NOT flips every bit in the register. Without a defined width there is no finite set of bits to flip, so the operation is meaningless. Two's complement negation also needs a width so the sign bit and wrap behaviour are defined. Choose 8, 16, 32 or 64 to match the register you are modelling.

      What is a nibble?

      A nibble is four bits, half a byte. It maps cleanly to one hexadecimal digit, which is why hex dumps and colour codes group bits in fours. The place values in a nibble are 1, 2, 4 and 8, summing to 15 when all bits are set.

      Can the Binary Calculator divide binary numbers?

      Yes. Division returns the quotient in binary, with the decimal check shown alongside. Division by zero is rejected. Remainders follow integer division rules unless a wider precision mode is selected for a specific problem.

      Does the calculator send binary input to a server?

      No. All arithmetic and conversion run locally in the browser. Input values are not uploaded, which matters when the strings come from memory dumps, keys or internal addresses.

      Summary

      The Binary Calculator performs base-2 arithmetic, converts to and from decimal through powers of two, and applies bitwise AND, OR, XOR, NOT and shifts with an optional register width. Adding 10101010 and 11001100 yields 101110110 (170 + 204 = 374), with carries shown column by column.

      Two's complement negation and bitwise NOT require a bit width; unbounded mode keeps results mathematically exact. Place values, nibbles and bytes are listed so binary strings used in masks, permissions and flags can be read without guessing.