Home › Math & Science › Binary Calculator
Binary Calculator
Use this free binary calculator to add, subtract, multiply and divide binary numbers, and to run bitwise AND, OR, XOR and NOT operations plus left and right bit shifts. Type two binary numbers — numbers made only of the digits 0 and 1 — pick an operation, and the calculator shows the answer in binary, decimal and hexadecimal at the same time. It runs entirely in your browser, with no sign-up and nothing to install.
Binary numbers may be up to 16 digits long. Spaces are ignored. For NOT, the answer is flipped within the length of A, so ~1011 is 0100.
Bits at a glance
Each box is one bit. The top row is A, the middle row is B, and the bottom row is the result.
How it works
Binary is the counting system computers use. Where decimal numbers use ten digits (0 to 9) and each place is worth ten times the one to its right, binary uses only two digits (0 and 1) and each place is worth twice the one to its right. Reading a binary number from right to left, the place values are 1, 2, 4, 8, 16, 32, 64 and so on. To find the decimal value of a binary number, add up the place values that have a 1 under them and ignore the places with a 0. For example, 1011 has 1s in the 8, 2 and 1 places, so it equals 8 + 2 + 1 = 11, and 1101 equals 8 + 4 + 1 = 13.
Addition in binary follows the same idea as decimal addition, with one simpler rule: 0 + 0 is 0, 0 + 1 and 1 + 0 are both 1, and 1 + 1 is 0 with a carry of 1 to the next column. That carry is what makes a sum like 1011 + 1101 grow to five digits. Subtraction borrows from the next column the same way, and a negative result shows a minus sign. Multiplication is repeated addition: each 1 in the second number adds a shifted copy of the first. Division gives you both a quotient and a remainder, just like long division in decimal, and dividing by zero is not allowed — the calculator will tell you so rather than giving a meaningless answer.
The bitwise operations work on one pair of bits at a time, matching up the bits of the two numbers by position. AND returns 1 only when both bits are 1, so it masks bits off: 1010 AND 1100 is 1000, because only the leftmost position has a 1 in both numbers. OR returns 1 when either bit is 1, which is how programmers turn individual bits on: 1010 OR 1100 is 1110. XOR returns 1 only when the two bits are different, so 1010 XOR 1100 is 0110; it is used to toggle bits and to build simple checksums. NOT flips every bit of a single number, turning 0s into 1s and 1s into 0s, and because a flipped number needs a fixed width to make sense, this calculator flips within the length of the number you typed, so NOT of 1011 is 0100.
Shifts move all the bits sideways. A left shift by n moves every bit n places to the left and fills the new places on the right with zeros; each single left shift doubles the value, so shifting left by three multiplies by eight. A right shift moves bits to the right and drops the bits that fall off the end, halving the value for each shift. Programs use shifts instead of multiplication and division whenever the factor is a power of two, because they are faster. The shift amount box is only used for shift operations.
Every answer is shown three ways because each base has its own job. Binary is what the hardware stores, decimal is what people read most easily, and hexadecimal is the shorthand programmers use, since one hex digit stands for exactly four binary digits — 11000 in binary is 24 in decimal and 0x18 in hex, far easier to type into code or compare at a glance. The bit diagram beside the calculator draws each bit as a box, so you can see which positions are set in each input and in the result.
Worked example
Suppose you are checking a small piece of code and need 1011 + 1101. First convert each number to decimal: 1011 is 8 + 2 + 1 = 11, and 1101 is 8 + 4 + 1 = 13, so the decimal sum is 11 + 13 = 24.
Now add them column by column, starting from the right. The rightmost column is 1 + 1, which is 0 with a carry of 1. The next two columns are each 1 + 0 plus the carried 1, giving 0 with another carry. The leftmost column is 1 + 1 plus the carried 1, which is 1 with a carry of 1, and that final carry becomes a new leftmost digit. Reading the result from left to right gives 11000.
Check the answer: 11000 has 1s in the 16 and 8 places, so it equals 16 + 8 = 24, matching the decimal sum. In hexadecimal, 24 is 0x18, since 24 divided by 16 is 1 with a remainder of 8. Type 1011 and 1101 into the calculator, choose Add, and it shows the same three answers.
FAQ
What is a binary number?
A binary number is a number written using only the digits 0 and 1. Each position in a binary number stands for a power of two — 1, 2, 4, 8, 16, 32 and so on, reading from right to left — instead of the powers of ten used in ordinary decimal numbers. Computers store and process all data this way, because a single bit can only be off (0) or on (1).
How do I convert binary to decimal by hand?
Write the place values 1, 2, 4, 8, 16 and so on above the binary digits, starting with 1 over the rightmost digit. Add together the place values that sit under a 1 and ignore the ones under a 0. For example, 1011 has 1s under 8, 2 and 1, so it equals 8 + 2 + 1 = 11 in decimal.
What is the difference between AND, OR and XOR?
AND gives 1 only where both input bits are 1, so it masks bits off. OR gives 1 where either input bit is 1, so it turns bits on. XOR gives 1 where the two bits are different, which makes it useful for toggling bits and for simple checksums. Each operation is applied to one pair of bits at a time.
What does a left shift do to a binary number?
A left shift moves every bit one or more places to the left and fills the empty places on the right with zeros. Each shift left by one doubles the value, so shifting left by three multiplies the number by eight. A right shift does the opposite: it moves bits to the right and drops the bits that fall off the end, which divides the value by two for each shift.
Why does the calculator also show a hexadecimal result?
Hexadecimal is the shorthand programmers use for binary, because one hex digit stands for exactly four binary digits. A long binary number such as 11000 is much easier to read and compare as 0x18, so showing it next to the binary and decimal answers saves a separate conversion step.