The binary calculator performs the full set of operations programmers need on base-2 numbers: arithmetic (addition, subtraction, multiplication, division, exponentiation), bitwise logic (AND, OR, XOR, NOT), and shift operators (left shift, right shift). Each result is shown in binary, decimal, and hexadecimal at the same time so you can verify by hand or copy directly into source code. Inputs can be entered in any of the three bases — useful when you have a hex constant from a datasheet, a decimal value from a spec, or a binary literal from a bitmap — and arbitrary-precision arithmetic via BigNumber.js means there is no 32-bit or 53-bit overflow ceiling. Common uses: debugging bitwise flag operations, building netmasks, decoding hardware registers, calculating two's-complement values, and learning how computers actually compute.
What is Binary?
Binary is the numeral system computers actually use. It has exactly two symbols, 0 and 1, because the physical hardware — transistors, magnetic domains, optical pits — can reliably represent two distinct states (off/on, low/high voltage) and almost nothing else with the same speed and reliability. Every higher-level structure in computing — text, images, audio, network packets, instructions — is, at the lowest level, just bits.
Each binary digit is called a bit. Eight bits form a byte (the smallest individually addressable unit on almost all modern computers); 16 bits a half-word; 32 or 64 bits a word, matching the CPU's native register width. Within a byte, bits are numbered from 0 (least significant, rightmost) to 7 (most significant, leftmost). The bit at position k contributes 2^k to the value when set.
Binary is a positional system just like decimal, but with base 2 instead of base 10. The binary number 1010 expands as 1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 8 + 0 + 2 + 0 = 10 in decimal. The leading digit is the most significant — same convention as decimal. To convert decimal to binary, repeatedly divide by 2 and record the remainders bottom-up; to convert binary to decimal, sum the powers of 2 at each set bit.
Binary's importance is not just historical: every computational primitive — arithmetic, addresses, file formats, network protocols — is defined in terms of bits and byte alignment. Understanding binary directly is what lets a programmer reason about overflow, alignment, endianness, compression, and the cost of operations. Even high-level languages that hide bits expose them when performance matters (bitsets, bloom filters, RoaringBitmap, CRC checksums, hash functions).
How to do binary calculations?
Binary arithmetic follows the same column-by-column algorithm you learned for decimal — the only difference is that the alphabet has two symbols instead of ten, so the carry/borrow rules are tighter.
- Binary Addition
- Same column algorithm as decimal, but the largest single-digit sum is 1 + 1 = 10₂ (which is 2 in decimal, written as 0 in this column with a 1 carried left).
- Single-column rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1). With an incoming carry: 1+1+1=11 (write 1, carry 1).
- Example: 1011 (11) + 1101 (13) = 11000 (24). Verify by adding column-wise from the right with carries.
- Hardware adds binary numbers exactly this way using cascaded full adders; modern CPUs add a 64-bit pair in a single clock cycle by computing all carries in parallel (carry-lookahead).
- Binary Subtraction
- Subtraction column rules: 0-0=0, 1-0=1, 1-1=0, 0-1 needs a borrow from the next column (gives 1 in this column, subtracts 1 from the column to the left).
- Inside CPUs, subtraction is almost never done by a separate borrowing circuit. Instead, a-b is computed as a + (~b + 1) — addition with the two's-complement of b — using the same adder.
- Example: 1011 (11) - 100 (4) = 111 (7). Or via two's complement: ~100 + 1 in 4 bits = 1100, then 1011 + 1100 = 10111, drop the carry-out, leaves 0111 = 7.
- This is why integers in C, Java, and most other languages can wrap around past INT_MIN/INT_MAX silently: a + 1 wraps to INT_MIN when a == INT_MAX because the carry-out gets discarded.
- Binary Multiplication
- Each bit of the multiplier is multiplied against the entire multiplicand and the partial products are summed, shifted by the bit's position.
- Single-bit rules: 0×anything=0, 1×anything=anything (just copy it).
- Example: 101 (5) × 11 (3) = partial products 101 (×1) and 1010 (×2, shifted left one place) summed = 1111 (15).
- Hardware does this with a multiplier circuit; multiplying two 64-bit values is typically a few clock cycles on modern x86 (IMUL) but used to be expensive on early CPUs — much slower than addition. This is why many old codebases use shift-and-add tricks.
- When one operand is a power of 2, multiplication degenerates to a left shift (n × 8 == n << 3). Compilers do this automatically as a strength reduction; the same is true for division by powers of 2 turning into right shifts.
- Binary Division
- Binary long division proceeds bit-by-bit: shift the divisor over to align with the dividend's high bits, subtract if it fits (writing a 1 in the quotient), shift right, repeat. The remainder is whatever is left after the last subtraction.
- Practical Notes
- Writing place values above the columns (..., 16, 8, 4, 2, 1) is the fastest way to convert binary to decimal by hand. Each '1' contributes its place value; sum them up.
- Use hex as a halfway notation: every 4 binary digits is one hex digit, so 1010 1011 = 0xAB, no arithmetic needed. This is why memory dumps and color codes use hex.
- Watch for word-size when computing in a real language: JavaScript bitwise operators silently truncate operands to 32-bit signed integers, so any computation involving bits 31+ behaves surprisingly. This calculator uses BigNumber.js to avoid that.
Beyond manual practice and this calculator, every general-purpose programming language supports binary literals (0b1010 in JS, Python, Rust, C++14+) and a full set of bitwise operators. For embedded work, refer to your chip's datasheet — register bit layouts are almost always defined in binary.
Binary/Decimal Conversion table
| Binary | Decimal |
|---|
| 0000 | 0 |
| 0001 | 1 |
| 0010 | 2 |
| 0011 | 3 |
| 0100 | 4 |
| 0101 | 5 |
| 0110 | 6 |
| 0111 | 7 |
| 1000 | 8 |
| 1001 | 9 |
| 1010 | 10 |
| 1011 | 11 |
| 1100 | 12 |
| 1101 | 13 |
| 1110 | 14 |
| 1111 | 15 |
Frequently Asked Questions
Because binary only has two symbols, 0 and 1 — the symbol "2" simply does not exist in this number system. Once you reach a count of two in any positional numeral system, you must wrap to the next place value. In decimal, 9 + 1 = 10 for exactly the same reason: 9 is the last single-digit symbol, and adding 1 forces a carry into the tens column. In binary, 1 + 1 produces 0 in the ones column and carries 1 into the twos column, written as 10. The value is two — the only thing that changed is the notation. This is also why programmers sometimes joke "there are 10 kinds of people in the world: those who understand binary and those who don't." Every positional system works this way, including hexadecimal: F + 1 = 10 (sixteen), and ternary: 2 + 1 = 10 (three).
Two's complement is the universal representation for signed integers in modern hardware, and it works by reinterpreting the most significant bit (MSB) as a negative weight. In 8 bits, the MSB has weight −128 instead of +128. So 11111111 in two's complement is −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1, and 10000000 is exactly −128. To negate a number: flip every bit (one's complement) and add 1. Example: +5 = 00000101 → flip to 11111010 → add 1 = 11111011 = −5. Two's complement has three desirable properties that drove its universal adoption: (1) there is only one zero (00000000), not two like in sign-magnitude; (2) addition works the same for signed and unsigned numbers — the same adder circuit handles both; (3) the carry-out of the high bit is discarded, giving natural modular arithmetic and predictable overflow behavior. The trade-off: the negative range is one larger than the positive range (e.g., 8-bit: −128 to +127), and abs(INT_MIN) overflows.
Bitwise operators are not academic curiosities — they appear constantly in performance-sensitive code, system code, and protocols. AND (&) tests bits and applies masks: status & 0x04 checks if the third bit is set, a common pattern for reading status flags or extracting fields from a packed structure. OR (|) sets bits: flags = flags | LOG_INFO turns on a flag without disturbing others. XOR (^) toggles bits or detects differences: x ^ x is always 0, used in checksums; XOR-swap exchanges two variables without a temporary; XOR-encryption with a key. NOT (~) inverts all bits and is mostly used in conjunction with AND to clear specific bits: flags = flags & ~LOG_DEBUG turns off LOG_DEBUG without touching others. These four operations are also the building blocks of higher-level abstractions: bitmaps, bloom filters, RoaringBitmap, IP netmasks (ip & netmask gives the network address), color blending in graphics, and hash functions. Almost every CPU implements them as single-cycle instructions; in tight loops they outperform any conditional alternative.
Left shift (<<) of any kind is unambiguous: pad with zeros on the right, drop bits off the left. Right shift has two flavors and you need to know which. Logical right shift (>>> in JavaScript and Java, lsr on ARM) always pads with 0 on the left, treating the number as unsigned — 0xFF >>> 1 = 0x7F. Arithmetic right shift (>> in JavaScript, Java, C with signed types; asr on ARM) replicates the sign bit, preserving the sign of a two's-complement number — −2 >> 1 = −1, not 0x7FFFFFFE. This matters: for unsigned bitfields, use logical; for signed integers, use arithmetic. Rotation (no native operator in C or JS, intrinsic _rotl/_rotr on x86) wraps bits around end-to-end instead of dropping them off the edge — useful in cryptography (AES, ChaCha all use rotations) and in fixed-width hash functions where you need a balanced spread of bits. JavaScript's regular << silently truncates the result to 32 bits, so shifts past bit 31 cause surprises; this calculator uses BigNumber.js to keep results exact at any bit width.
Because 4 binary digits map exactly to 1 hex digit, with no remainder. 0000 to 1111 corresponds to 0 to F. A 32-bit value is 32 binary digits but only 8 hex digits, which fits on one line of source and is easier to read at a glance. Hex preserves all the bit structure: each hex character tells you exactly 4 bits, so 0xDEADBEEF immediately tells a programmer the bit pattern, while 11011110101011011011111011101111 makes the eye blur. Octal (base 8) is older and groups bits 3-at-a-time — it was common on 12-bit and 36-bit machines from the 1960s — but octal does not divide 32 evenly, so you get awkward gaps; hex won. RGB color codes (#FF8800), MAC addresses, UUIDs, memory addresses, file checksums, and Unicode code points (U+1F600) are all in hex for exactly this reason. When debugging bit-level code, learning to translate hex digits to and from their 4-bit binary patterns by sight is one of the highest-leverage skills.
Because the decimal number 0.1 has no exact binary representation. In base 2, 0.1 is the non-terminating repeating fraction 0.000110011001100... — analogous to how 1/3 is 0.333... in decimal. IEEE 754 double-precision rounds this to 52 bits of mantissa, giving an approximation slightly larger than 0.1. The same applies to 0.2. When you add the two rounded approximations and convert back to decimal, the residual error becomes visible: 0.30000000000000004. Powers of 2 — 0.5, 0.25, 0.125 — and integer multiples of them — 0.75, 0.625 — are exactly representable. Anything else has rounding error. For financial calculations or when exact decimal arithmetic is required, use a Decimal library (BigDecimal in Java, Decimal in Python, BigNumber.js in JavaScript) or scale to integer cents. For binary integer arithmetic — what this calculator focuses on — there is no rounding error: integers up to 2^53 fit exactly in a double-precision float, and BigNumber.js takes us past even that limit.
Depends on the language and the integer type. C/C++ int is implementation-defined but typically 32-bit signed: −2,147,483,648 to +2,147,483,647 (about ±2.1 billion). long long is 64-bit signed: about ±9.2 quintillion. JavaScript Number is a 64-bit double-precision float, so it represents integers exactly up to 2^53 − 1 = 9,007,199,254,740,991 (called Number.MAX_SAFE_INTEGER); beyond that, consecutive integers are no longer distinguishable. JavaScript bitwise operators (&, |, ^, <<, >>, ~) cheat differently: they always truncate both operands to 32-bit signed integers, then convert back to Number. So 0x100000000 | 0 == 0, which surprises people. ES2020 added BigInt (literal 123n) for arbitrary precision. Python natively has arbitrary-precision int — no overflow ever — but pays a runtime cost. Rust requires you to choose: u32, i64, u128, etc., and overflow is checked in debug mode but wraps in release. This calculator uses BigNumber.js for arbitrary precision, so binary arithmetic with hundreds of digits works as expected.
The use of binary patterns in mathematics goes back much further than Leibniz — ancient Egyptian multiplication used binary decomposition, and the Indian scholar Pingala described what amounts to a binary positional system around 200 BCE for analyzing Sanskrit meter. But Gottfried Wilhelm Leibniz, in his 1703 paper Explication de l'Arithmétique Binaire, gave the first systematic Western treatment of binary as a complete numeral system, with addition, subtraction, multiplication, and division rules — and explicitly observed that all numbers could be represented using only 0 and 1. Leibniz was inspired in part by descriptions of the I Ching's hexagrams, whose 64 figures map exactly to 6-bit binary numbers. The next leap took 250 years: George Boole's 1854 algebra of logic showed that propositions could be manipulated with two truth values, and Claude Shannon's 1937 MIT master's thesis A Symbolic Analysis of Relay and Switching Circuits proved that Boolean algebra implemented in electrical relays could perform arbitrary computation — the foundation of all digital computers. Konrad Zuse's Z3 (1941) and the ENIAC (1945) followed shortly after. Every CPU today is, in the end, an enormous Boolean-circuit machine following Shannon's blueprint.