Base-2 (Binary) Number System
Master the language of computers - binary! Understanding base-2 is essential for cybersecurity professionals working with low-level systems, network protocols, and data representation.
What is Binary?
Binary (base-2) is the fundamental number system used by computers. It uses only two digits: 0 and 1, representing the two states of electronic switches: OFF and ON.
Key Characteristics:
- Base: 2
- Digits: 0 and 1 (called "bits")
- Place Values: Powers of 2 (1, 2, 4, 8, 16, 32, etc.)
- Usage: All digital computing, networking, data storage
Bit
Binary Digit (0 or 1)
Smallest unit of data
Byte
8 bits grouped together
Can represent 256 values (0-255)
Understanding Binary Place Values
Each position in a binary number represents a power of 2, starting from 2⁰ on the right.
Example: The binary number 11010110
2⁷ (128) |
2⁶ (64) |
2⁵ (32) |
2⁴ (16) |
2³ (8) |
2² (4) |
2¹ (2) |
2⁰ (1) |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
128 | 64 | 0 | 16 | 0 | 4 | 2 | 0 |
Decimal Value: 128 + 64 + 16 + 4 + 2 = 214
Converting Binary to Decimal
Method 1: Place Value Addition
Example: Convert 1011₂ to decimal
1011₂ = 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 1×8 + 0×4 + 1×2 + 1×1 = 8 + 0 + 2 + 1 = 11₁₀
Method 2: Doubling Method
Start from the left, double and add:
1011₂: Start with 0 See 1: 0×2 + 1 = 1 See 0: 1×2 + 0 = 2 See 1: 2×2 + 1 = 5 See 1: 5×2 + 1 = 11₁₀
Converting Decimal to Binary
Method 1: Division by 2
Example: Convert 45₁₀ to binary
45 ÷ 2 = 22 remainder 1 22 ÷ 2 = 11 remainder 0 11 ÷ 2 = 5 remainder 1 5 ÷ 2 = 2 remainder 1 2 ÷ 2 = 1 remainder 0 1 ÷ 2 = 0 remainder 1 Read remainders from bottom to top: 101101₂
Method 2: Powers of 2 Subtraction
Find the largest power of 2 that fits:
45₁₀: 45 - 32 (2⁵) = 13 → 1 13 - 16 (2⁴) = no → 0 13 - 8 (2³) = 5 → 1 5 - 4 (2²) = 1 → 1 1 - 2 (2¹) = no → 0 1 - 1 (2⁰) = 0 → 1 Result: 101101₂
Binary Arithmetic
Binary Addition
Rules: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 (0 carry 1) Example: 1011 + 1101 ------ 11000
Binary Subtraction
Rules: 0 - 0 = 0 1 - 0 = 1 1 - 1 = 0 0 - 1 = 1 (borrow 1) Example: 1101 - 1010 ------ 0011
Binary in Cybersecurity
1. IP Addresses and Subnet Masks
IPv4 addresses are 32-bit binary numbers:
192.168.1.1 = 11000000.10101000.00000001.00000001 255.255.255.0 = 11111111.11111111.11111111.00000000
2. File Permissions (Unix/Linux)
Permissions use 3 bits each for read, write, execute:
rwx = 111₂ = 7₁₀ r-x = 101₂ = 5₁₀ r-- = 100₂ = 4₁₀ chmod 755 = rwxr-xr-x
3. Bitwise Operations in Programming
Operation | Symbol | Example | Use Case |
---|---|---|---|
AND | & | 1010 & 1100 = 1000 | Masking bits |
OR | | | 1010 | 1100 = 1110 | Setting flags |
XOR | ^ | 1010 ^ 1100 = 0110 | Encryption |
NOT | ~ | ~1010 = 0101 | Bit flipping |
Practice Exercises
Exercise 1: Binary to Decimal
Convert these binary numbers to decimal:
- 10110₂
- 11111111₂
- 10000001₂
Exercise 2: Decimal to Binary
Convert these decimal numbers to binary:
- 73₁₀
- 255₁₀
- 128₁₀
Exercise 3: Binary Operations
Perform these operations:
- 1011₂ + 1110₂
- 11001₂ - 1010₂
- 1100₂ AND 1010₂
Exercise 4: Real-World Application
Given the IP address 172.16.254.1, convert the first octet (172) to binary.
Interactive Binary Converter
Decimal to Binary
Binary to Decimal
Next Steps
Great job learning binary! Continue your journey: