Calculating in binary
Enter two numbers
Use the digits 0 and 1 in the two number boxes. Spaces, underscores, a 0b prefix and a leading minus sign are accepted, and long values are handled exactly.
Choose the operation
Pick +, −, ×, ÷, mod, AND, OR or XOR. Division returns the whole-number part; use mod for the remainder.
Read the result
The answer appears in binary, with its decimal and hex equivalents. A negative result also shows its 8-bit two's complement form.
Convert a decimal
The lower panel takes an ordinary base-10 whole number and shows the same value written in base 2, base 8 and base 16.
Worked examples
Adding 1011 (eleven) and 110 (six) gives 10001, which is 17. A bitwise AND of 1100 and 1010 keeps only the positions where both have a 1, giving 1000, or 8.
Subtracting the larger number from the smaller, 110 minus 1011, gives -101, which is -5. The calculator adds the 8-bit two's complement, 11111011, which is how a computer would store -5 in a single byte.
1011 + 110 1100 AND 1010 110 − 1011
10001 (decimal 17, hex 11) 1000 (decimal 8) −101 (decimal −5, 8-bit two's complement 11111011)
Bitwise operations in plain words
- AND
- A 1 only where both numbers have a 1. Often used to test whether a particular flag or setting bit is switched on.
- OR
- A 1 wherever either number has a 1. Used to switch a flag on without disturbing the others.
- XOR
- A 1 where exactly one of the two numbers has a 1. Applying the same XOR twice restores the original, which is why it appears in simple checksums.
- Two's complement
- How most computers hold values below zero: flip each bit of the matching positive number, then add one. In a byte, -5 becomes 11111011.
Questions people ask
How do you add binary numbers by hand?
Work from the right, as with decimal. 0 + 0 is 0, 0 + 1 is 1, and 1 + 1 is 0 carry 1. With a carry, 1 + 1 + 1 is 1 carry 1. So 1011 + 110 gives 1 then 0 carry 1, then 0 carry 1, then 0 carry 1, and the final carry makes 10001.
What is 42 in binary?
101010. That is 32 + 8 + 2. In octal it is 52 and in hex 2A. Type any whole decimal number into the converter at the bottom of the tool to see the same three forms for your own values.
Can it handle fractions or binary points?
No. The calculator works with whole numbers only, which is what bitwise operations need. For fractions in ordinary decimal arithmetic, use the fraction calculator. For hexadecimal input, the hex calculator offers the same operations.
Where your data goes
Binary arithmetic is done by script on this page. The numbers you enter are not sent or stored.
Checked against the tool on