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.
| Operation | Rule | Result |
|---|---|---|
| AND | 1 only if both bits are 1 | 1000 |
| OR | 1 if either bit is 1 | 1110 |
| XOR | 1 if the bits differ | 0110 |
| NOT 1100 (4-bit) | flip every bit | 0011 |
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.