Binary Calculator

Do exact integer arithmetic and bitwise logic in binary, octal, decimal, hex or any base up to 36, and see every result in all four bases with its bit pattern.

Result10001 (base 2)

Digits in the chosen base. A leading minus sign, 0b/0o/0x prefix (bases 2, 8, 16), spaces and underscores are allowed.

Result

10001 (base 2)

  • Binary10001
  • Octal21
  • Decimal17
  • Hexadecimal11
  • 8-bit two's complement0001 0001

Arithmetic uses exact arbitrary-precision integers, so no digits are lost to rounding.

How this was calculated

A = 1011₂ = 11₁₀.

B = 110₂ = 6₁₀.

11 + 6 = 17 (decimal).

How binary arithmetic and bitwise operations work

Arithmetic works the same in every base: 1011₂ is 8 + 2 + 1 = 11 and 110₂ is 4 + 2 = 6, so their sum is 17, written 10001₂, 21₈ or 11₁₆. This calculator uses exact arbitrary-precision integers, so very long inputs never lose digits to floating-point rounding.

Integer division gives a whole-number quotient and a remainder that satisfy A = B × quotient + remainder. The quotient is truncated toward zero and the remainder keeps the sign of A, the rule used by C, Java and JavaScript: −7 ÷ 2 = −3 remainder −1.

Bitwise operations compare the two numbers bit by bit inside a fixed word size. AND keeps a 1 only where both bits are 1, OR where either is 1, and XOR where exactly one is 1. NOT flips every bit of A.

Bitwise operations on 1100 and 1010
OperationRuleResult
AND1 only if both bits are 11000
OR1 if either bit is 11110
XOR1 if the bits differ0110
NOT 1100 (4-bit)flip every bit0011

Two's complement, word size and shifts

Computers store negative integers in two's complement: invert the bits of the positive value and add 1. In 8 bits, NOT 5 is 1111 1010, which reads as 250 unsigned or −6 signed. Pick 8, 16, 32 or 64 bits to match the register or data type you are modeling.

A left shift by n multiplies by 2ⁿ and drops any bits that move past the top of the word. A logical right shift (>>>) fills the vacated bits with 0, while an arithmetic right shift (>>) copies the sign bit, so −8 >> 1 is −4 but −8 >>> 1 is 124 in an 8-bit word.

Any base from 2 to 36, powers and modulo

Choose Other base to work in any base from 2 to 36. Digits run 0–9 and then A–Z, so base 36 uses all ten numerals and 26 letters. The inputs are converted to exact integers, the operation is done once, and the answer is written back in your base as well as binary, octal, decimal and hexadecimal.

Example in base 3: 21₃ is 2 × 3 + 1 = 7 and 12₃ is 1 × 3 + 2 = 5, so 21₃ × 12₃ = 35 = 1 × 27 + 0 × 9 + 2 × 3 + 2 = 1022₃.

Power (A ^ B) multiplies A by itself B times using exact integers: 11₂ ^ 11₂ is 3³ = 27 = 11011₂. Modulo uses floored division, so the answer takes the sign of B: 17 mod 5 = 2 and −7 mod 3 = 2. The Divide operation shows the truncated remainder instead (−7 ÷ 3 = −2 remainder −1).

Converting only?

To change a single number from one base to another without doing arithmetic, use the Binary and Hex Calculator, which converts between bases 2 to 36.

How to use the Binary Calculator

Choose the base and operation, then enter the numbers.

  1. Choose the input base

    Select binary, octal, decimal, hexadecimal or another base from 2 to 36 for both inputs.

  2. Pick an operation

    Choose add, subtract, multiply, divide, power, modulo, a bitwise operation or a shift.

  3. Enter the numbers

    Type A and B (or the shift amount) and choose a word size for bitwise results.

  4. Read the result

    See the answer in all four bases with the two's-complement bit pattern and the working.

References

Frequently asked questions

How do you add binary numbers?

Add column by column from the right: 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 10, which writes 0 and carries 1. For example 1011 + 110 = 10001, or 11 + 6 = 17 in decimal.

Why is NOT 5 equal to −6?

NOT flips every bit. In 8 bits 5 is 0000 0101, so NOT 5 is 1111 1010. Read as a signed two's-complement number that is −6; read as unsigned it is 250.

Can I enter negative or hexadecimal numbers?

Yes. Choose the input base, then type digits with an optional minus sign and an optional 0b, 0o or 0x prefix. Spaces and underscores between digits are ignored.

Last updated . Results are estimates for informational purposes only.