Binary Calculator
Programmers, engineering students, and network administrators constantly switch between base-2 and base-10 representations – whether it’s calculating subnet masks, debugging firmware, or verifying an ALU circuit by hand. Doing binary arithmetic manually is slow and error-prone, especially with multi-byte values. A binary calculator eliminates the grind by handling conversions, arithmetic, and bitwise operations instantly.
How Binary Numbers Work
Binary is a positional numeral system with a radix (base) of 2. Each digit – called a bit – can only be 0 or 1. The position of each bit determines its weight, increasing as a power of 2 from right to left:
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Weight | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The binary number 10011011 equals 128 + 16 + 8 + 2 + 1 = 155 in decimal.
Groups of 4 bits map directly to one hexadecimal digit, and groups of 3 bits map to one octal digit, which is why hex and octal are widely used as shorthand for binary data.
How Do You Add Binary Numbers?
Binary addition follows four simple rules:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (0 with a carry of 1)
When both bits and an incoming carry are 1, the result is 11 (1 with a carry of 1). Consider adding 10110 (22) and 01101 (13):
10110
+ 01101
-------
100011 (= 35)
The calculator above performs this column-by-column carry logic automatically, supporting values up to 32 bits.
Binary Subtraction
Subtraction in binary can be done directly (borrowing from the next left column when needed) or by using the two’s complement method – the same approach hardware uses.
To subtract B from A:
- Find the two’s complement of B: invert every bit, then add 1
- Add the result to A
- Discard any carry beyond the most significant bit
Example: 10110 − 01101
- Invert
01101→10010 - Add 1 →
10011 - Add to
10110:10110 + 10011 = 101001 - Discard the overflow bit →
01001(= 9 in decimal, which is 22 − 13)
Binary Multiplication and Division
Multiplication works like long multiplication in decimal, but is simpler because each multiplier bit is only 0 or 1. For each 1-bit in the multiplier, write a copy of the multiplicand shifted left by the bit position; for each 0-bit, write zeros. Then add all the partial products.
Division mirrors decimal long division: shift the divisor left, compare with the current remainder, write 1 if the divisor fits, otherwise write 0, and continue with the next bit. The calculator handles both operations and returns the quotient and remainder.
Converting Between Binary and Decimal
Binary to decimal
Multiply each bit by its positional weight and sum the results. The binary value 110101 equals:
1×32 + 1×16 + 0×8 + 1×4 + 0×2 + 1×1 = 53
Decimal to binary
Repeatedly divide by 2 and record the remainders:
| Step | Division | Quotient | Remainder |
|---|---|---|---|
| 1 | 53 ÷ 2 | 26 | 1 |
| 2 | 26 ÷ 2 | 13 | 0 |
| 3 | 13 ÷ 2 | 6 | 1 |
| 4 | 6 ÷ 2 | 3 | 0 |
| 5 | 3 ÷ 2 | 1 | 1 |
| 6 | 1 ÷ 2 | 0 | 1 |
Reading remainders bottom to top: 110101.
What Are Bitwise Operations?
Bitwise operators work on individual bits of binary numbers. They are essential in low-level programming, cryptography, and graphics.
| Operation | Symbol | Rule | |
|---|---|---|---|
| AND | & | 1 only if both bits are 1 | |
| OR | ` | ` | 1 if at least one bit is 1 |
| XOR | ^ | 1 if bits differ | |
| NOT | ~ | Inverts every bit | |
| Left shift | << | Shifts bits left, fills with 0 | |
| Right shift | >> | Shifts bits right, fills with 0 (logical) or sign bit (arithmetic) |
Example – AND between 1100 and 1010:
1100
& 1010
------
1000
XOR is particularly useful for toggling flags and for swap algorithms that work without a temporary variable.
Binary to Hex and Octal Conversion
Because 16 = 2⁴ and 8 = 2³, converting between binary and hex or octal requires no arithmetic – just grouping bits.
Binary → hex: group into nibbles (4 bits) from the right, then replace each group with its hex digit.
10110011 → 1011 0011 → B3
Binary → octal: group into triads (3 bits) from the right, then replace each group with its octal digit.
10110011 → 010 110 011 → 263
The calculator above outputs all three representations simultaneously.
Practical Uses of Binary Calculation
- Subnetting: IPv4 addresses and subnet masks are 32-bit binary values. CIDR notation like
/26means the first 26 bits are the network portion – a binary AND between the IP and mask reveals the network address. - Embedded systems: Register values in microcontrollers are configured by setting or clearing individual bits with bitwise OR and AND.
- File permissions: Unix permissions like
chmod 755map directly to a 9-bit binary pattern (111101101). - Color encoding: A 24-bit RGB value such as
FF8C00is three 8-bit binary channels packed into a single integer. - Error detection: Parity bits and CRC checksums are computed with XOR operations on binary data.
This calculator is for educational and reference purposes. Verify critical results against your development tools or system specifications before deploying to production.