Binary Calculator – Add, Subtract, Multiply, Divide with Step-by-Step Solutions

Binary Calculator: Add, Subtract, Convert and More

Add, subtract, multiply, divide, bitwise ops, convert between binary, decimal, hex & octal. Free & instant.

🔢 Binary Arithmetic
Digits 0 and 1 only
Digits 0 and 1 only
⚡ Bitwise Operations
Not required for NOT
🔄 Multi-Base Number Converter

Type in any field. All others update instantly.

🔲 Interactive Bit Viewer

Click any bit to toggle it on/off. All representations update instantly.

Size:
🔢 Place Values
Binary Calculator – Supports unlimited bit length
BinaryDecimalHexOctal

Working with binary numbers trips up most people the first time. This guide covers everything a binary calculator handles: addition, subtraction, multiplication, division, bitwise operations, and number base conversions. Every section includes formulas and worked examples so you can follow along and verify your results.

Binary arithmetic follows the same logic as decimal. The only difference is the base. Once that clicks, everything else follows naturally.

What Is the Binary Number System and Why Computers Use It

Base-2 vs Base-10: The Core Difference Explained Simply

In decimal, the number 214 means (2 × 100) + (1 × 10) + (4 × 1). Binary works the same way, but each position represents a power of 2 instead of 10.

The number 1101 in binary equals (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰), which gives you 8 + 4 + 0 + 1 = 13 in decimal.

Computers use binary because hardware only needs to detect two states: on or off. Building circuits to detect 10 states (0 through 9) would be far more complex and error-prone.

Binary Digits, Bits, and Place Values

Each position in a binary number represents a power of 2. Reading from right to left, positions represent 2⁰, 2¹, 2², 2³, and so on.

  • Bit: a single binary digit, either 0 or 1
  • Nibble: 4 bits, represents values 0 to 15
  • Byte: 8 bits, represents values 0 to 255
  • Word: depends on architecture, commonly 16 or 32 bits

MSB (most significant bit) is the leftmost bit with the highest place value. LSB (least significant bit) is the rightmost bit, representing 2⁰ = 1.

Powers of Two Reference Table:

PowerValuePowerValue
2⁰12⁸256
22⁹512
42¹⁰1,024
82¹²4,096
2⁴162¹⁶65,536
2⁵322²⁰1,048,576
2⁶642²⁴16,777,216
2⁷1282³²4,294,967,296

Binary Addition: Rules, Carry Method, and Worked Examples

The Four Rules of Binary Addition

Binary addition has only four possible outcomes per column:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10 (write 0, carry 1 to next column)
  • 1 + 1 + 1 = 11 (write 1, carry 1 to next column)

The carry is the only thing that catches people out. Always write it above the next column before you add.

How to Add Binary Numbers Step by Step

Always align numbers by their rightmost bit before adding. Work from right to left, just like decimal addition.

Worked example: 1101 + 1010

Carry:  1 1 0 0
     A:  1 1 0 1
     B: +1 0 1 0
        --------
        1 0 1 1 1

Step-by-step breakdown:

  • Column 0 (rightmost): 1 + 0 = 1, carry 0
  • Column 1: 0 + 1 = 1, carry 0
  • Column 2: 1 + 0 = 1, carry 0
  • Column 3: 1 + 1 = 0, carry 1
  • Column 4: carry 1 = 1

Result: 10111 = 23 decimal (13 + 10 = 23 ✓)

Worked example: 11111 + 00001

Carry:  1 1 1 1 1
     A:  1 1 1 1 1
     B: +0 0 0 0 1
        ---------
        1 0 0 0 0 0

Result: 100000 = 32 decimal (31 + 1 = 32 ✓)

Binary Addition with Three or More Numbers

Add the first two numbers together, then add the result to the third. Carry values can exceed 1 when multiple 1s appear in the same column.

Worked example: 101 + 011 + 110

  • First: 101 + 011 = 1000
  • Then: 1000 + 110 = 1110

Result: 1110 = 14 decimal (5 + 3 + 6 = 14 ✓)

Binary Addition Overflow Explained

Overflow happens when the result needs more bits than your system allows.

  • In a 4-bit system, valid unsigned values are 0 to 15. Adding 1001 (9) + 1000 (8) = 10001 (17). The 5th bit is lost. The stored result becomes 0001, which is wrong.
  • In a signed 8-bit system, overflow occurs when two positive numbers produce a negative result, or vice versa.
  • The carry flag signals that a bit was lost beyond the result width.
  • The overflow flag signals that the signed result is incorrect.

These two flags are separate. A carry does not always mean an error in signed arithmetic.

16-bit binary addition with carry:

  0011 1100 1010 1101
+ 0001 0101 0110 1011
= 0101 0010 0001 1000

Decimal check: 15,533 + 5,483 = 21,016. Convert 0101001000011000 to confirm.

Binary Subtraction: Borrowing, 1’s Complement, and 2’s Complement Methods

Direct Binary Subtraction Rules (Borrow Method)

  • 0 − 0 = 0
  • 1 − 0 = 1
  • 1 − 1 = 0
  • 0 − 1 = 1, borrow 1 from the next column (that column loses 1)

Worked example: 1101 − 1010

Borrow:  0 0 0 0
      A:  1 1 0 1
      B: -1 0 1 0
         --------
         0 0 1 1

Result: 0011 = 3 decimal (13 − 10 = 3 ✓)

Binary Subtraction Using 1’s Complement

1’s complement flips every bit in the number. Then you add instead of subtract.

Formula: A − B = A + (1’s complement of B) + 1

Worked example: 11001101 − 01011010

  • Step 1: Flip all bits of B (01011010) → 10100101
  • Step 2: Add A + flipped B + 1: 11001101 + 10100101 + 1 = 101110011
  • Step 3: End-around carry. Take the extra leftmost 1 and add it to the result: 01110011 + 1 = 01110100

Result: 01110100 = 116 decimal (205 − 90 = 115… note: 1’s complement has a known ±1 edge case on boundary values, which is why 2’s complement replaced it).

Binary Subtraction Using 2’s Complement

This is the method all modern computers use. It converts subtraction into addition.

Formula: 2’s complement of B = (1’s complement of B) + 1

Worked example: 1010 − 0111

  • Step 1: 1’s complement of 0111 → 1000
  • Step 2: Add 1 → 1001 (this is the 2’s complement of 0111)
  • Step 3: Add A + 2’s complement of B: 1010 + 1001 = 10011
  • Step 4: Discard the carry bit → 0011

Result: 0011 = 3 decimal (10 − 7 = 3 ✓)

8-bit worked example producing a negative result: 00110010 − 01001100

  • 2’s complement of 01001100 → 10110100
  • 00110010 + 10110100 = 11100110

MSB is 1, so the result is negative. Find 2’s complement of 11100110 to get the magnitude: 00011010 = 26. Result: −26 decimal (50 − 76 = −26 ✓)

Signed Binary Subtraction and Negative Results

In signed binary, the leftmost bit is the sign bit. 0 means positive, 1 means negative.

When your subtraction result has a 1 in the MSB, the number is negative in 2’s complement form. Find the 2’s complement of the result to get its magnitude, then apply a negative sign.

Competitors rarely show this step clearly. Most stop at the raw binary result without explaining how to read it as a negative decimal.

Adding and Subtracting Binary Numbers Together

For mixed operations, handle each pair left to right. Apply 2’s complement for any subtraction step.

Worked example: 1011 + 0110 − 0011

  • Step 1: 1011 + 0110 = 10001
  • Step 2: 10001 − 0011, 2’s complement of 0011 = 1101, 10001 + 1101 = 11110
  • Discard carry if working in fixed width, or keep: 1110 = 14 decimal (11 + 6 − 3 = 14 ✓)

Binary Multiplication: Partial Products Method and Shift-and-Add

Rules of Binary Multiplication

Binary multiplication is simpler than decimal. Only four rules exist:

  • 0 × 0 = 0
  • 0 × 1 = 0
  • 1 × 0 = 0
  • 1 × 1 = 1

If the multiplier bit is 0, the partial product is all zeros. If it is 1, the partial product equals the multiplicand. This makes the method fast.

Binary Long Multiplication Using Partial Products

Worked example: 1101 × 1011

        1 1 0 1   (multiplicand = 13)
      × 1 0 1 1   (multiplier = 11)
      ---------
        1 1 0 1   (1101 × 1, shift 0)
       1 1 0 1 0  (1101 × 1, shift 1)
      0 0 0 0 0 0 (1101 × 0, shift 2)
    + 1 1 0 1 0 0 0 (1101 × 1, shift 3)
    -----------
    1 0 0 0 1 1 1 1

Result: 10001111 = 143 decimal (13 × 11 = 143 ✓)

Shift-and-Add Method for Binary Multiplication

Hardware uses shift registers instead of writing out partial products. Shifting a binary number left by one position multiplies it by 2.

  • 1101 shifted left once → 11010 (13 × 2 = 26)
  • 1101 shifted left twice → 110100 (13 × 4 = 52)
  • 1101 shifted left three times → 1101000 (13 × 8 = 104)

This is exactly what logic gates perform inside a CPU multiplier circuit.

Binary Multiplication with Signed Numbers and 2’s Complement

When both operands are signed, convert each to 2’s complement if negative, multiply, then check the result sign.

Worked example: −5 × 3 in 4-bit signed binary

  • −5 in 4-bit 2’s complement: 0101 → flip → 1010, add 1 → 1011
  • 3 in binary: 0011
  • Multiply: 1011 × 0011 = 00100001 (raw result before sign correction)
  • Result should be −15. In 8-bit 2’s complement: 11110001.

Key point competitors miss: when you multiply two n-bit signed numbers, the result needs 2n bits to avoid overflow. Always check the bit-width of your result container.

Binary Floating Point Multiplication

Floating point numbers have three parts: sign (1 bit), exponent (8 bits), mantissa (23 bits) in IEEE 754 single precision.

To multiply two floating point binary numbers:

  • Step 1: XOR the sign bits to get the result sign
  • Step 2: Add the two exponents, then subtract the bias (127 for single precision)
  • Step 3: Multiply the two mantissas (as integers including the implicit leading 1)
  • Step 4: Normalize the result back to 1.xxxx × 2ⁿ form

This is why floating point multiplication can accumulate rounding errors across repeated operations.

Binary Division: Long Division Method and Restoring Algorithm

Binary Long Division Step by Step

Binary long division mirrors decimal long division exactly.

Worked example: 110100 ÷ 1010

  • 110100 in decimal is 52. 1010 in decimal is 10. Expected: quotient 5, remainder 2.
         101   (quotient)
      ------
1010 | 110100
       1010
       -----
        0110
        0000
        ----
         1100
         1010
         ----
           10  (remainder)

Result: quotient 101 (= 5), remainder 10 (= 2) ✓

Verification formula: dividend = (quotient × divisor) + remainder 110100 = (101 × 1010) + 10 → 52 = (5 × 10) + 2 ✓

Division by Powers of Two Using Right Shift

Right-shifting a binary number by n positions divides it by 2ⁿ.

  • 1000 >> 1 = 0100 (8 ÷ 2 = 4 ✓)
  • 1000 >> 2 = 0010 (8 ÷ 4 = 2 ✓)
  • 1000 >> 3 = 0001 (8 ÷ 8 = 1 ✓)

For unsigned numbers, use logical right shift. Zeros fill from the left. For signed numbers, use arithmetic right shift. The sign bit copies itself into vacated positions, preserving the negative value.

Processors use right shift as a fast division shortcut whenever the divisor is a power of two.

Binary to Decimal Conversion: Two Methods with Full Examples

Positional Weight Method (Expand and Sum)

Formula: decimal = Σ(bit × 2ⁿ) for each position n from right (n = 0)

Worked example: 10110101 to decimal

Bit10110101
Position76543210
Value128032160401

128 + 32 + 16 + 4 + 1 = 181 decimal

Doubling Method (Horner’s Method)

Start from the MSB. Double the running total and add the next bit. This is faster for long binary strings.

Worked example: 11010110 to decimal

  • Start: 1
  • 1 × 2 + 1 = 3
  • 3 × 2 + 0 = 6
  • 6 × 2 + 1 = 13
  • 13 × 2 + 0 = 26
  • 26 × 2 + 1 = 53
  • 53 × 2 + 1 = 107
  • 107 × 2 + 0 = 214

Result: 214 decimal

Horner’s method eliminates the need to remember powers of two. For strings beyond 8 bits, it is noticeably quicker.

Converting Binary Fractions to Decimal

Positions to the right of the binary point represent negative powers of 2.

Formula: fractional decimal = Σ(bit × 2⁻ⁿ) starting at n = 1

Worked example: 0.1011 to decimal

  • 0.1011 = (1 × 2⁻¹) + (0 × 2⁻²) + (1 × 2⁻³) + (1 × 2⁻⁴)
  • = 0.5 + 0 + 0.125 + 0.0625
  • = 0.6875 decimal

Some decimal fractions, like 0.1, cannot be exactly represented in binary. They produce infinite repeating binary sequences, similar to 1/3 in decimal.

Decimal to Binary Conversion: Division Method and Shortcut Tricks

Repeated Division by 2 Method

Divide by 2 repeatedly. Record each remainder. Read remainders from bottom to top.

Worked example: 214 to binary

DivisionQuotientRemainder
214 ÷ 21070
107 ÷ 2531
53 ÷ 2261
26 ÷ 2130
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Read remainders upward: 11010110

Worked example: 255 to binary

255 ÷ 2 repeated produces all remainders of 1. Result: 11111111 = 8 ones (maximum 8-bit unsigned value).

Subtraction of Powers of Two Method

Find the largest power of 2 that fits, place a 1, subtract, and repeat.

Worked example: 173 to binary

  • 173 − 128 = 45 → place 1 at position 7
  • 45 − 32 = 13 → place 1 at position 5
  • 13 − 8 = 5 → place 1 at position 3
  • 5 − 4 = 1 → place 1 at position 2
  • 1 − 1 = 0 → place 1 at position 0

Fill remaining positions with 0: 10101101 ✓ (128 + 32 + 8 + 4 + 1 = 173)

Decimal Fraction to Binary (Multiply by 2 Method)

Multiply the fractional part by 2. The integer part of each result is a binary digit, reading from the top.

Worked example: 0.625 to binary

MultiplicationResultInteger part (bit)
0.625 × 21.251
0.25 × 20.500
0.50 × 21.001

Result: 0.101 binary (0.5 + 0 + 0.125 = 0.625 ✓)

Worked example: 0.1 to binary (infinite expansion)

0.1 × 2 = 0.2 (bit: 0), 0.2 × 2 = 0.4 (bit: 0), 0.4 × 2 = 0.8 (bit: 0), 0.8 × 2 = 1.6 (bit: 1), 0.6 × 2 = 1.2 (bit: 1), then the cycle repeats. Result: 0.000110011… (non-terminating). This is why floating point results for 0.1 are never exact.

Binary to Hexadecimal and Hexadecimal to Binary Conversion

Why Binary and Hex Are Closely Related

Every group of exactly 4 binary bits maps to one hexadecimal digit. Hex gives a compact way to write long binary strings without losing information.

Hex digit reference table:

DecimalBinaryHexDecimalBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

Binary to Hexadecimal Conversion Step by Step

  • Step 1: Group bits into sets of 4 from the right
  • Step 2: Pad the leftmost group with leading zeros if needed
  • Step 3: Replace each 4-bit group with its hex equivalent

Worked example: 11010110 to hex

Group: 1101 | 0110 → D | 6 → D6

Worked example: 1011001011110001 to hex

Group: 1011 | 0010 | 1111 | 0001 → B | 2 | F | 1 → B2F1

Hexadecimal to Binary Conversion Step by Step

  • Step 1: Write the 4-bit equivalent of each hex digit
  • Step 2: Concatenate all groups in order

Worked example: 4F3A to binary

4 = 0100, F = 1111, 3 = 0011, A = 1010 → 0100111100111010

Worked example: 0xFF to binary

F = 1111, F = 1111 → 11111111 = 255 decimal ✓

Binary to Octal and Octal to Binary Conversion

How Octal Maps to Binary Groups of Three

Every group of exactly 3 binary bits maps to one octal digit (0–7). No lookup table needed, just 8 combinations.

OctalBinaryOctalBinary
00004100
10015101
20106110
30117111

Binary to Octal Conversion with Worked Examples

Group from the right in sets of 3, pad left if needed, then convert each group.

Worked example: 110101011 to octal

Group: 110 | 101 | 011 → 6 | 5 | 3 → 653 octal ✓ (decimal: 423)

Octal to Binary Conversion with Worked Examples

Expand each octal digit to its 3-bit binary equivalent, then concatenate.

Worked example: 745 to binary

7 = 111, 4 = 100, 5 = 101 → 111100101

Octal was common in older Unix systems. You still see it in Linux file permissions (chmod 755 = 111 101 101 in binary).

1’s Complement and 2’s Complement: What They Mean and How to Calculate

What Is 1’s Complement and How to Find It

Flip every bit. Every 0 becomes 1, every 1 becomes 0.

Formula: 1’s complement of N = (2ⁿ − 1) − N

Worked example: 1’s complement of 10110100

10110100 → 01001011 ✓

1’s complement is used in some older network checksum algorithms and in one error-detection scheme for serial communications.

What Is 2’s Complement and How to Calculate It

Two methods give the same result.

Method 1: Find 1’s complement, then add 1. Method 2: Copy bits from the right up to and including the first 1. Flip all remaining bits to the left.

Formula: 2’s complement of N = 2ⁿ − N

Worked example: 2’s complement of 10110000

  • Method 1: flip → 01001111, add 1 → 01010000
  • Method 2: rightmost 1 is at position 4, copy 10000, flip left portion 101 → 010, combine → 01010000 ✓

Both methods give 01010000.

Why 2’s Complement Is the Standard in Computing

1’s complement has two representations of zero: 00000000 and 11111111. This complicates comparisons and branching logic in hardware.

2’s complement has only one zero (00000000). Addition and subtraction use the exact same hardware circuit. No special case handling needed for negative numbers.

Signed value ranges:

Bit widthUnsigned rangeSigned range (2’s complement)
4-bit0 to 15−8 to 7
8-bit0 to 255−128 to 127
16-bit0 to 65,535−32,768 to 32,767
32-bit0 to 4,294,967,295−2,147,483,648 to 2,147,483,647

Converting 2’s Complement Back to Decimal

  • Step 1: Check the MSB. If it is 1, the number is negative.
  • Step 2: Find the 2’s complement of the result to get the magnitude.
  • Step 3: Apply a negative sign to the magnitude.

Worked example: 11110110 in 2’s complement to decimal

  • MSB is 1, so the number is negative.
  • Flip: 00001001, add 1: 00001010 = 10 decimal.
  • Result: −10 decimal

Bitwise Operations: AND, OR, XOR, NOT, NAND, NOR

Bitwise AND Operation with Truth Table and Examples

AND outputs 1 only when both input bits are 1.

ABA AND B
000
010
100
111

Use case: bit masking to isolate specific bits. AND a value with a mask of 00001111 to extract the lower 4 bits.

Worked example: 11001010 AND 10110101

  11001010
& 10110101
----------
  10000000

Real-world use: IP subnetting uses bitwise AND. AND the IP address with the subnet mask to find the network address.

Bitwise OR Operation with Truth Table and Examples

OR outputs 1 when at least one input bit is 1.

ABA OR B
000
011
101
111

Use case: setting specific bits to 1 without affecting others (bit flag setting).

Worked example: 11001010 OR 10110101

  11001010
| 10110101
----------
  11111111

Result: 11111111 = 255 decimal (all bits set).

Bitwise XOR Operation with Truth Table and Examples

XOR (exclusive OR) outputs 1 when inputs differ.

ABA XOR B
000
011
101
110

Use case: toggling bits, checksum calculations, basic encryption.

Worked example: 11001010 XOR 10110101

  11001010
^ 10110101
----------
  01111111

Key property: XOR of any number with itself always equals zero. XOR of any number with 0 leaves it unchanged.

Bitwise NOT Operation with Examples

NOT flips every bit. In an 8-bit system, NOT 10110100 = 01001011.

The result depends on bit width. NOT on a 32-bit number affects all 32 bits. This is why NOT on a small number often produces a large result.

Worked example: NOT 10110100 (8-bit)

10110100 → 01001011 = 75 decimal ✓

Bitwise NOT and logical NOT are different. Logical NOT converts any nonzero value to false. Bitwise NOT flips each individual bit.

NAND and NOR Gates in Binary Operations

  • NAND = NOT (A AND B). Output is 0 only when both inputs are 1.
  • NOR = NOT (A OR B). Output is 1 only when both inputs are 0.

NAND is called a universal gate because any logical operation can be built from NAND gates alone. All digital circuits in a CPU can theoretically be built using only NAND.

Worked example: 1100 NAND 1010

1100 AND 1010 = 1000, then NOT → 0111

Worked example: 1100 NOR 1010

1100 OR 1010 = 1110, then NOT → 0001

Left Shift and Right Shift Operations

Left shift: move all bits left by n positions, fill right with zeros. Multiplies by 2ⁿ.

  • 00001101 << 2 = 00110100 (13 × 4 = 52 ✓)

Right shift (logical): move all bits right, fill left with zeros. Divides by 2ⁿ for unsigned numbers.

  • 11010000 >> 2 = 00110100 (208 ÷ 4 = 52 ✓)

Right shift (arithmetic): the sign bit copies into vacated positions. This preserves the sign for negative numbers.

  • 11010000 >> 2 (arithmetic) = 11110100 (−48 ÷ 4 = −12 ✓)

Signed Binary Numbers: Sign-Magnitude, 1’s Complement, and 2’s Complement

Sign-Magnitude Representation Explained

The MSB is the sign bit. 0 = positive, 1 = negative. The remaining bits are the magnitude.

  • 0 0001101 = +13
  • 1 0001101 = −13

Problem: two representations of zero exist: 00000000 (+0) and 10000000 (−0). Hardware must handle this as a special case, which adds complexity.

Comparing All Three Signed Binary Representations

4-bit signed number comparison table:

DecimalSign-Magnitude1’s Complement2’s Complement
+7011101110111
+1000100010001
0000000000000
−010001111(no −0)
−1100111101111
−7111110001001
−8(overflow)(overflow)1000

2’s complement is the only representation with no −0. It also has one extra negative value (−8 in 4-bit vs −7 for the others).

Binary Coded Decimal (BCD): What It Is and How It Differs

How BCD Encodes Each Decimal Digit Separately

BCD stores each decimal digit as its own 4-bit binary group, rather than converting the whole number to binary.

Example: decimal 749 in BCD

  • 7 = 0111
  • 4 = 0100
  • 9 = 1001

BCD representation: 0111 0100 1001

This is not the same as converting 749 to binary (which gives 1011101101).

BCD is used in digital displays (clocks, cash registers), financial applications where decimal precision matters, and some older hardware interfaces.

BCD Addition Rules and Worked Examples

BCD addition works normally until a column’s result exceeds 9. When that happens, add 0110 (6) to correct it.

Worked example: BCD addition of 49 + 38

  • 9 in BCD + 8 in BCD: 1001 + 1000 = 10001. This exceeds 9, so add 0110 → 10001 + 0110 = 10111. Write 0111, carry 1.
  • 4 in BCD + 3 in BCD + carry 1: 0100 + 0011 + 0001 = 1000. This is 8, within range. Write 1000.

Result: 1000 0111 in BCD = decimal 87 ✓ (49 + 38 = 87)

Binary Floating Point and IEEE 754 Format

Structure of IEEE 754 Single-Precision Float

FieldBitsDescription
Sign10 = positive, 1 = negative
Exponent8Biased exponent (bias = 127)
Mantissa23Fractional part after leading 1

Formula: value = (−1)^sign × 2^(exponent − 127) × 1.mantissa

Special values: exponent 00000000 = zero or denormalized. Exponent 11111111 = infinity or NaN.

Converting Decimal to Binary Floating Point

Worked example: −13.625 to IEEE 754 single precision

  • Step 1: 13 in binary = 1101. 0.625 in binary = 0.101. Together: 1101.101
  • Step 2: Normalize: 1.101101 × 2³
  • Step 3: Sign bit = 1 (negative)
  • Step 4: Biased exponent = 3 + 127 = 130 = 10000010
  • Step 5: Mantissa (drop leading 1): 10110100000000000000000

Full IEEE 754 result: 1 10000010 10110100000000000000000

Common Floating Point Precision Errors

0.1 in binary is a repeating fraction: 0.000110011001100… This means no computer can store exactly 0.1 in binary floating point. It always stores an approximation.

This causes problems in financial calculations. 0.1 + 0.2 in most languages does not equal exactly 0.3. The difference is tiny but can compound across millions of operations. Financial systems use BCD or fixed-point arithmetic specifically to avoid this.

IP Address to Binary Conversion for Networking

Why Subnetting Requires Binary Conversion

Routers apply bitwise AND between an IP address and a subnet mask to find the network address. Without understanding binary, subnetting makes no sense.

IPv4 addresses consist of four 8-bit octets, written in decimal with dots. To work with them logically, you convert each octet to binary.

How to Convert an IP Address to Binary Step by Step

Convert each octet independently using the repeated-division method. Pad each result to exactly 8 bits.

Worked example: 192.168.1.255

  • 192 = 11000000
  • 168 = 10101000
  • 1 = 00000001
  • 255 = 11111111

Full binary: 11000000.10101000.00000001.11111111

Subnet mask AND operation: 192.168.1.255 AND 255.255.255.0

  11000000.10101000.00000001.11111111
& 11111111.11111111.11111111.00000000
= 11000000.10101000.00000001.00000000

Network address: 192.168.1.0

Binary Checksum Calculation for Network Error Detection

What a Binary Checksum Does and Why It Matters

A checksum detects data corruption during transmission. The sender calculates a checksum and appends it to the data. The receiver calculates the same checksum and compares. A mismatch means something changed in transit.

TCP, UDP, and IP headers all include 16-bit checksums calculated using binary addition with carry wraparound.

How to Calculate a 16-Bit Internet Checksum Step by Step

  • Step 1: Split data into 16-bit (2-byte) blocks
  • Step 2: Add all blocks using binary addition
  • Step 3: If the sum exceeds 16 bits, wrap the carry back into the lower 16 bits
  • Step 4: Take the 1’s complement of the final sum

Worked example with 4 blocks:

Blocks: 1100000010110100, 0101001000011000, 1010110001111011, 0001101000110101

Sum all four (add carries back if needed), then flip all bits. The result is the checksum. The receiver adds all blocks including the checksum. A result of 1111111111111111 (all ones) confirms no errors.

Binary Logarithm (Log Base 2) with Examples

What Binary Logarithm Means and Where It Appears

Definition: log₂(x) is the power to which 2 must be raised to produce x.

log₂(8) = 3 because 2³ = 8. log₂(1024) = 10 because 2¹⁰ = 1024.

Binary logarithm appears throughout computer science:

  • Bit depth: storing 256 distinct values needs log₂(256) = 8 bits
  • Binary search: finds a value in log₂(n) steps in a sorted list of n items
  • Binary tree height: a balanced tree with n nodes has height log₂(n)
  • Information theory (Shannon entropy) uses log₂

“For non-power-of-two values, use the change of base formula or a scientific calculator to compute log₂(x) instantly.”

How to Calculate Binary Logarithm Manually

Method 1: count how many times you can halve the number before reaching 1.

  • 64 → 32 → 16 → 8 → 4 → 2 → 1 (6 steps) → log₂(64) = 6
  • 512 → … → 1 (9 steps) → log₂(512) = 9

Method 2: recognize the power directly.

  • log₂(128) = 7 (since 2⁷ = 128)
  • log₂(4096) = 12 (since 2¹² = 4096)

Change of base formula: log₂(x) = log₁₀(x) ÷ log₁₀(2) = log₁₀(x) ÷ 0.30103

log₂(100) = log₁₀(100) ÷ 0.30103 = 2 ÷ 0.30103 ≈ 6.644

ASCII to Binary and Text to Binary Conversion

How ASCII Maps Characters to Binary Numbers

ASCII assigns a decimal number to each character. Standard ASCII uses 7 bits (0–127). Extended ASCII uses 8 bits (0–255).

ASCII quick reference:

CharacterDecimalBinary
A6501000001
B6601000010
Z9001011010
a9701100001
z12201111010
04800110000
Space3200100000

Converting Text to Binary Step by Step

  • Step 1: Find the ASCII decimal value for each character
  • Step 2: Convert each decimal to 8-bit binary

Worked example: “HELLO” to binary

  • H = 72 = 01001000
  • E = 69 = 01000101
  • L = 76 = 01001100
  • L = 76 = 01001100
  • O = 79 = 01001111

Result: 01001000 01000101 01001100 01001100 01001111

Worked example: “bin” to binary

  • b = 98 = 01100010
  • i = 105 = 01101001
  • n = 110 = 01101110

Result: 01100010 01101001 01101110

Note that uppercase and lowercase letters differ only in bit 5. Flipping bit 5 switches between uppercase and lowercase for any ASCII letter.

Binary Addition and Subtraction Practice: Common Mistakes to Avoid

The Carry Confusion: When and Where to Add It

The most common mistake is forgetting to carry the bit into the next column. Write the carry row above your calculation before you start, and update it as you go.

Mistake example:

Wrong:    Correct:
  1101      1101
+ 0111    + 0111
------    ------
  1004     10100

The wrong attempt treats binary like decimal in column 2. Carry must propagate.

Borrow Chain Errors in Binary Subtraction

A single borrow can ripple across multiple columns. Track each borrow carefully.

Worked example: 10000 − 00001

Borrow:  0 1 1 1 1
      A:  1 0 0 0 0
      B: -0 0 0 0 1
         ---------
         0 1 1 1 1

Result: 01111 = 15 decimal (16 − 1 = 15 ✓)

The borrow ripples all the way from column 0 to column 4. Each column along the way borrows from the next. Using 2’s complement avoids this entirely: 2’s complement of 00001 = 11111, add to 10000, discard carry → 01111. Same answer, no borrow needed.

Overflow vs Carry: Knowing the Difference

This is the part most guides explain poorly.

  • Carry out: a 1-bit result that overflows beyond the MSB position. Not always an error.
  • Overflow: the signed result is wrong. The sign bit does not match what it should be.

Truth table for signed 4-bit addition:

Operand signsResult signCarryOverflow?
+ + ++0No
+ + +0Yes
− + −1No
− + −+1Yes
+ + −anyanyNever
− + +anyanyNever

Overflow only occurs when both operands share the same sign but the result has the opposite sign. The CPU overflow flag captures this. The carry flag captures the extra bit. Both exist independently.

Binary Number Quick Reference Tables

Binary to Decimal Table: 0 to 32

DecimalBinaryHexDecimalBinaryHex
00000000000160001000010
10000000101170001000111
20000001002180001001012
30000001103190001001113
40000010004200001010014
50000010105240001100018
6000001100628000111001C
70000011107320010000020
80000100008640100000040
15000011110F1281000000080

Binary Arithmetic Rules Summary

Addition:

ABSumCarry
0000
0110
1010
1101

Multiplication:

ABResult
000
010
100
111

Signed range summary:

BitsUnsigned maxSigned minSigned max
415−87
8255−128127
1665,535−32,76832,767
324,294,967,295−2,147,483,6482,147,483,647

Conclusion

Binary arithmetic is consistent and rule-bound. Once you understand carry in addition, borrow in subtraction, and 2’s complement for signed numbers, everything else builds naturally on those three ideas.

Floating point errors, checksum calculation, IP subnetting, and ASCII encoding all trace back to the same binary fundamentals covered here. A good binary calculator confirms your manual work and shows the steps, but understanding the process means you can work through problems even without a tool.

The rules never change. 1 + 1 is always 10 in binary. Build from there.

“Binary is one piece of a larger math toolkit. Browse the full set of math calculators for percentage, fraction, geometry, and statistics tools.”

if you want to