Binary Calculator for Arithmetic, Bitwise Operations & Base Conversion
A binary calculator works with numbers represented in base 2, where every digit is either 0 or 1. This calculator goes beyond simple binary-to-decimal conversion: it can perform binary arithmetic, bitwise operations, logical shifts, signed two's-complement calculations, modulo operations, and conversions between bases from 2 through 36.
Use the calculator to add, subtract, multiply, divide, or find the remainder of binary values; evaluate AND, OR, XOR, and NOT operations; perform left and right shifts; and inspect the result at the bit level. The converter also shows decimal, hexadecimal, and octal representations alongside the requested base.
For computer-science and engineering work, representation matters as much as arithmetic. A bit pattern such as 11111101 can represent 253 as unsigned 8-bit data but −3 as signed 8-bit two's-complement data. The calculator therefore separates the mathematical result, fixed-width register representation, and signed interpretation instead of treating them as the same quantity.
Large integer conversions are handled with exact arbitrary-precision integer arithmetic rather than forcing values into ordinary floating-point precision. This is especially important beyond JavaScript's Number.MAX_SAFE_INTEGER, which is 2⁵³ − 1 (9,007,199,254,740,991); JavaScript's BigInt type is designed for integers outside that exact range.
1. What Is a Binary Calculator?
A binary calculator is a computational tool designed to work with the base-2 number system used extensively in digital electronics and computer systems. Unlike decimal notation, which uses the digits 0 through 9, binary uses only 0 and 1.
Each binary position represents a power of two:
For example:
This positional structure is one reason binary arithmetic fits digital hardware so naturally. NIST material on mathematics and engineering in computer science describes binary as a positional number system in which each digit corresponds to a power of two, and notes its close relationship with computer arithmetic.
A useful binary calculator should therefore answer more than “what is this number in decimal?” It should help users understand the relationship between the bit pattern, the numeric value, the operation being performed, and, where relevant, the fixed-width representation. That is the purpose of this calculator.
2. How Binary Numbers Work
Every binary digit is called a bit. Starting from the rightmost bit, the positions have weights:
| Bit Position | Power of 2 | Positional Value |
|---|---|---|
| 0 | 2⁰ | 1 |
| 1 | 2¹ | 2 |
| 2 | 2² | 4 |
| 3 | 2³ | 8 |
| 4 | 2⁴ | 16 |
| 5 | 2⁵ | 32 |
| 6 | 2⁶ | 64 |
| 7 | 2⁷ | 128 |
So 11001010₂ becomes:
The important distinction is that the binary string itself is a representation, while its interpretation depends on the context. For example, the eight-bit pattern 11111101₂ has an unsigned value of 253, but under signed two's-complement interpretation it represents −3. The same bits therefore do not automatically imply the same signed numeric value.
3. Binary Arithmetic: Addition, Subtraction, Multiplication, Division and Modulo
Binary arithmetic follows the same broad mathematical principles as decimal arithmetic, but every column contains only the digits 0 and 1.
Binary Addition
The basic rules are:
For example, adding 170 and 15:
10101010 + 00001111 ---------- 10111001
The result is 10111001₂ = 185₁₀. The calculator exposes the carry chain so users can inspect how each column contributed to the final result.
Binary Subtraction
Binary subtraction can be performed with borrowing, but computer systems commonly implement subtraction through two's-complement addition. For 5 − 8, the eight-bit forms are:
Interpreted as signed 8-bit two's complement: 11111101₂ = −3. This approach is consistent with computer arithmetic conventions; NIST's computer-science material describes subtraction through adding the two's complement of the subtrahend.
Binary Multiplication
Binary multiplication is particularly simple because each multiplier bit is either 0 or 1:
1011 (11 in decimal)
× 101 (5 in decimal)
----------
1011
0000
+ 101100
----------
110111 (55 in decimal)The same shift-and-add structure is fundamental to digital arithmetic hardware.
Binary Division and Modulo
Binary division follows repeated quotient and remainder operations, analogous to long division in decimal notation. For 255 ÷ 2, the quotient is 127 with remainder 1. That remainder is important when converting a decimal integer to binary because repeated division by 2 generates the binary digits.
Binary modulo returns the remainder after division: 13 mod 5 = 3, which in binary is 1101₂ mod 101₂ = 11₂. The calculator explicitly validates modulo-by-zero rather than returning an invalid numerical result.
4. Bitwise AND, OR, XOR and NOT
Bitwise operations act on corresponding bits rather than treating an entire value as a single decimal quantity.
AND (&)
Produces 1 only when both input bits are 1.
11001100 & 10101010 ---------- 10001000
OR (|)
Produces 1 when at least one corresponding bit is 1.
11001100 | 10101010 ---------- 11101110
XOR (^)
Produces 1 when corresponding bits are different.
11001100 ^ 10101010 ---------- 01100110
NOT (~)
Reverses each bit within the register width.
~ 00001111 ---------- 11110000
XOR is widely used in low-level systems, masking, and cryptography. A crucial point is that NOT depends on the chosen width when interpreted as a fixed-size register. An eight-bit NOT operation and an unrestricted mathematical complement are not the same concept. For dedicated hexadecimal bitwise manipulation, examine our Hex Calculator.
5. Left Shift and Right Shift
A binary shift moves bits to the left or right. A left shift by one position is equivalent to multiplication by 2 when no significant information is discarded:
For fixed-width registers, however, bits shifted beyond the register width are discarded. That is why shift operations can create overflow or loss of high-order bits.
A right shift corresponds to integer division by a power of two for unsigned values: 10000000₂ >> 1 = 01000000₂. Signed right shifts require additional care: an arithmetic right shift preserves the sign bit (MSB) to maintain correct negative integer values, whereas a logical right shift injects leading zeros. The calculator explicitly distinguishes the operation from its resulting fixed-width representation rather than hiding the discarded or inserted bits.
6. Signed and Unsigned Binary Numbers
A binary value has no inherent “negative” meaning until a representation convention is chosen.
Unsigned Representation
With an 8-bit unsigned register, range is 0 to 255:
Signed Two's Complement
For an n-bit signed register, range is −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 (−128 to +127 for 8-bit):
Under 8-bit signed two's complement: 11111111₂ = −1, 11111110₂ = −2, and 11111101₂ = −3. This distinction is especially important when a binary calculator shows both a bitstream and a decimal answer.
7. How Two's Complement Works
Two's complement is a fixed-width representation used to encode signed integers in digital hardware. To find the two's complement of a positive binary value:
- Write the binary representation at the required register width.
- Invert every bit (1's complement).
- Add 1 to the least significant bit.
For example, using eight bits for +3:
The highest-order bit acts as the sign indicator in a fixed-width signed representation. The calculator's visualizer displays these stages explicitly during subtraction so the user can distinguish one's complement, adding 1, two's complement, and the final signed interpretation.
8. Binary Overflow and Carry-Out
Overflow is one of the easiest parts of fixed-width binary arithmetic to misunderstand. Suppose an unsigned eight-bit register contains 255 = 11111111₂ and we add 1 = 00000001₂. The mathematical result is 256, but 256 cannot be represented in eight unsigned bits.
The register therefore retains 00000000 while a carry-out of 1 indicates that a ninth bit was generated. A useful calculator shows both:
Signed overflow is a related but distinct concept. For an eight-bit signed two's-complement register, the maximum positive number is 127. Therefore 127 + 1 has mathematical result 128, which is outside the signed range [−128, 127]. The resulting bit pattern 10000000 represents −128. The calculator reports signed overflow rather than allowing the wrapped result to look like an ordinary successful calculation. NIST material specifically discusses overflow detection in computer arithmetic and fixed-point representations.
9. Binary to Decimal, Hexadecimal and Octal Conversion
Binary, hexadecimal and octal are closely related because their bases are powers of two:
- Binary to Decimal: Evaluate each bit as a power of two:
1011₂ = 11₁₀. - Binary to Hexadecimal: Because 16 = 2⁴, every hexadecimal digit corresponds to four binary bits:
1011 1001₂ = B9₁₆. For complex 64-bit word masking, consult the Advanced Hexadecimal Math, Bitwise & Converter. - Binary to Octal: Because 8 = 2³, binary digits can be grouped into sets of three:
101 110 01₂ → 271₈. - Hexadecimal to Binary: Reverse the process:
B₁₆ = 1011₂and9₁₆ = 1001₂, soB9₁₆ = 10111001₂.
The calculator provides these representations together, making it easier to cross-check a result without manually performing every conversion.
10. Convert Numbers Between Bases 2 Through 36
The calculator supports base conversion beyond the common binary, octal, decimal and hexadecimal systems, spanning bases from 2 through 36:
For bases above 10, additional alphanumeric symbols are used (0–9 followed by A–Z). The conversion principle relies on exact positional polynomial evaluation:
For large integers, exact integer arithmetic is especially important. Ordinary floating-point types cannot represent all integers above 2⁵³ − 1 exactly, while BigInt is intended for arbitrary-magnitude integers. This calculator preserves integer values using exact BigInt arithmetic rather than passing them through floating-point Number conversions.
11. Why Large Binary Calculations Need Exact Integer Arithmetic
JavaScript's standard Number type uses IEEE 754 double-precision floating-point format and guarantees exact integer representation only through:
Beyond that point, different consecutive integers collapse into the exact same floating-point value. MDN explicitly documents this limitation and recommends BigInt for larger exact integers. For example, the 64-bit unsigned integer maximum is:
This exactness matters for 64-bit registers, memory pointers, bit masks, cryptographic hashes, protocol headers, and network masks. For networking-specific bit manipulation and subnet calculations, use our IP Subnet Calculator.
12. Example: Calculate 170 + 15 in Binary
Suppose 170₁₀ = 10101010₂ and 15₁₀ = 00001111₂. Add them:
10101010 (170 in decimal) + 00001111 (15 in decimal) ---------- 10111001 (185 in decimal)
Convert the result back to decimal: 128 + 32 + 16 + 8 + 1 = 185.
The calculator presents these equivalent forms together so that the user can verify the result through multiple representations.
13. Practical Uses of a Binary Calculator
Binary arithmetic appears in many areas of computing and engineering because digital hardware stores and manipulates information as bits:
- Computer science: understanding binary arithmetic, bitwise operators, shifts, masks, and integer representations.
- Programming: checking results of AND, OR, XOR, NOT, shifts, modulo, and fixed-width register operations.
- Digital electronics: reasoning about ALU registers, logic operations, carry propagation, and binary encodings.
- Networking: examining binary representations of IP addresses, subnet masks, and protocol header flags.
- Systems programming: verifying signed versus unsigned values, register wrap, and word size boundaries.
- Data representation: converting values among binary, hexadecimal, octal, and decimal notation.
- Education: verifying hand-worked binary arithmetic and learning two's-complement representation step by step.
For advanced scientific formulas and numerical computations, you can also consult our Scientific Calculator.
14. Common Binary Calculation Mistakes
1010 is not one thousand ten; it means 1(2³) + 0(2²) + 1(2¹) + 0(2⁰) = 10 in decimal.
The result of an unrestricted integer calculation is not necessarily the same as the result stored in a fixed-size 8-bit or 16-bit register.
11111101 is 253 unsigned, but represents −3 as signed eight-bit two's complement.
A wrapped register result can look perfectly valid unless the carry or overflow condition is examined.
Converting a large integer through an ordinary floating-point number can silently truncate its exact value beyond 53 bits.
Each hexadecimal digit corresponds directly to four binary bits, which makes hexadecimal a compact representation of binary data.
15. What This Binary Calculator Can Do
This calculator combines several functions that are commonly separated across different tools:
Addition (+), Subtraction (−), Multiplication (×), Division (÷), and Modulo (%).
Bitwise AND, OR, XOR, and NOT with responsive column mapping.
Logical Left Shift (<<) and Arithmetic/Logical Right Shift (>>).
Configurable 8-bit, 16-bit, 32-bit, and 64-bit register widths.
Unsigned pure binary alongside signed two's-complement decoding.
Bijective conversions across any base from 2 through 36 with BigInt precision.
16. How to Use the Binary Calculator
Start by choosing the register size and whether the value should be interpreted as unsigned or signed two's complement.
Enter the first binary or decimal operand and, where required, enter the second operand. Choose the operation such as addition, subtraction, multiplication, division, modulo, AND, OR, XOR, NOT or a shift.
The result panel provides the calculated bit pattern together with equivalent numeric representations. For arithmetic operations, the derivation section explains the calculation and the bit visualizer shows how the individual columns behave.
For base conversion, select the source and target bases and enter the value exactly as written in that base. For large integers, the calculator preserves integer precision instead of passing the value through a standard floating-point representation.
Use Save / Restore when you want to revisit a previous calculation, and use the copy or export controls when the result needs to be transferred into notes, code documentation, spreadsheets or another workflow.
17. Use the Binary Calculator to Check the Whole Representation
Binary arithmetic becomes much easier to verify when the calculation, representation and interpretation are shown together.
Instead of calculating a result in binary and then manually checking it in decimal or hexadecimal, you can inspect the binary result, decimal value, hexadecimal form, octal form, bit-level operation, signed interpretation and overflow state in one place.
That makes the calculator useful both as a fast conversion tool and as a learning reference for binary arithmetic, computer architecture and low-level programming.