Binary Calculator (Add, Subtract, AND, OR, XOR, Shifts)

Add, subtract, multiply and divide binary, octal or hex numbers, or apply AND, OR, XOR, NOT and shifts at 8 to 64 bits. Answers shown in all four bases.

Only the digits of the chosen base. Spaces are ignored; a leading minus is allowed for arithmetic. You may start with 0b, 0o or 0x.

Results

Result in binary
1 0001
Result in octal
21
Result in decimal
17
Result in hexadecimal
11
Working (binary, then decimal check)
1011 + 110 = 10001 In decimal: 11 + 6 = 17

How it’s calculated

Binary uses only the digits 0 and 1, and each place is worth twice the one to its right (1, 2, 4, 8, 16, …). Arithmetic works like decimal arithmetic, but you carry as soon as a column reaches 2. Octal (base 8) and hexadecimal (base 16) are shorthand for binary: each octal digit stands for 3 bits and each hex digit for 4 bits.

0 + 0 = 0 0 + 1 = 1 1 + 1 = 10 (write 0, carry 1) AND: 1 only if both bits are 1 OR: 1 if either bit is 1 XOR: 1 if the bits differ NOT: flips every bit shift left by n: multiplies by 2ⁿ

Example: 1011 + 110. In decimal that is 11 + 6. Column by column from the right: 1 + 0 = 1; 1 + 1 = 10 (write 0, carry 1); 0 + 1 + carry 1 = 10 (write 0, carry 1); 1 + carry 1 = 10. Reading the result: 10001, which is 17 in decimal, 11 in hex. A bitwise example: 00001100 AND 00001010 = 00001000 (12 AND 10 = 8), because only the 8s bit is set in both.

Bitwise operations and bit width. The bitwise operations act on a fixed number of bits (8, 16, 32 or 64). Negative numbers are stored in two's complement: invert the bits of the positive number and add 1, so −1 at 8 bits is 11111111. NOT of 00001100 (12) at 8 bits is 11110011, which is 243 unsigned or −13 signed. A logical shift fills with zeros; an arithmetic shift right copies the sign bit so negative numbers stay negative.

To simply convert one number between bases (with no arithmetic), use the number base converter.

Frequently asked questions

How do I add binary numbers?

Add column by column from the right, just as in decimal, but 1 + 1 = 10 in binary, so write 0 and carry 1 to the next column. For example 1011 + 110 = 10001.

What is the difference between >> and >>>?

Both shift bits to the right. >>> (logical) always fills the left end with 0s. >> (arithmetic) copies the sign bit, so negative numbers stay negative. For positive numbers they give the same answer.

Why do I get a large number when I use NOT?

NOT flips every bit at the chosen width, so NOT 0 at 8 bits is 11111111 = 255 unsigned. As a signed number the same bits mean −1, which is shown under "signed".

Does subtraction give negative binary numbers?

For ordinary arithmetic the answer is shown with a minus sign (1 − 11 = −10). The bit patterns of two's complement are used only for the bitwise operations, where the width matters.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator