Binary & Number Systems
Convert between decimal, binary, and hex — essential for reading shellcode, network packets, and hashes.
Learning Objectives
- → Convert numbers between decimal, binary, and hexadecimal
- → Explain why binary matters in security (bit flags, shellcode, XOR)
- → Decode ASCII characters from their numeric values
- → Use hex in the context of file headers, hashes, and memory addresses
Computers only understand one thing: electricity is on or off. From this simple fact, everything in computing is built. Understanding binary and hex is not optional for security work — you'll encounter them constantly.
Why This Matters for Security
- Network packets are raw bytes — you need hex to read them
- Memory addresses are in hexadecimal
- Permissions in Linux use octal (base 8)
- Hashes like MD5, SHA-256 are displayed in hex
- Shellcode is written in binary/hex opcodes
- XOR (a key crypto operation) works on binary
The Decimal System (Base 10)
You already know this one. Each position is a power of 10:
1 4 2 3
│ │ │ └── 3 × 10⁰ = 3
│ │ └──── 2 × 10¹ = 20
│ └────── 4 × 10² = 400
└──────── 1 × 10³ = 1000
─────
1423
Binary (Base 2)
Each position is a power of 2. Only digits 0 and 1 exist.
1 0 1 1 0 1
│ │ │ │ │ └── 1 × 2⁰ = 1
│ │ │ │ └───── 0 × 2¹ = 0
│ │ │ └──────── 1 × 2² = 4
│ │ └─────────── 1 × 2³ = 8
│ └────────────── 0 × 2⁴ = 0
└───────────────── 1 × 2⁵ = 32
───
45
So 101101 in binary = 45 in decimal.
Converting Decimal → Binary
Repeatedly divide by 2, record remainders (read bottom to top):
45 ÷ 2 = 22 remainder 1 ←
22 ÷ 2 = 11 remainder 0 |
11 ÷ 2 = 5 remainder 1 | read upward
5 ÷ 2 = 2 remainder 1 |
2 ÷ 2 = 1 remainder 0 |
1 ÷ 2 = 0 remainder 1 ←
Result: 101101
Bits and Bytes
- 1 bit = one binary digit (0 or 1)
- 8 bits = 1 byte
- A byte can hold values from 0 (
00000000) to 255 (11111111) - 1 KB = 1024 bytes, 1 MB = 1024 KB, 1 GB = 1024 MB
Hexadecimal (Base 16)
Hex uses 16 digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15).
| Hex | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| F | 15 | 1111 |
Why hex? One hex digit represents exactly 4 bits. Two hex digits = 1 byte. Much shorter than writing 8 binary digits.
Binary: 1111 1010
Hex: F A
Decimal: 250
Reading Hex in Security Tools
Hex is always written with a 0x prefix or shown in groups:
Memory address: 0x7ffd3ab2c040
SHA-256 hash: a665a45920422f9d417e4867efdc4fb8...
Packet payload: 45 00 00 3c 1c 46 40 00 40 06 ...
ASCII — Text as Numbers
Every character on your keyboard has a number. ASCII maps 128 characters to values 0–127.
| Char | Decimal | Hex |
|---|---|---|
| A | 65 | 0x41 |
| a | 97 | 0x61 |
| 0 | 48 | 0x30 |
| space | 32 | 0x20 |
| ! | 33 | 0x21 |
Security uses:
- Buffer overflow shellcode is ASCII bytes
- SQL injection payloads are ASCII-encoded
- %41 in a URL is the letter 'A' (hex 41)
XOR — The Crypto Building Block
XOR (exclusive OR) is the most important bitwise operation in security:
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Rule: XOR is 1 only when inputs are different.
Key property: A XOR B XOR B = A
This means XOR is reversible with the same key — the foundation of stream ciphers.
Plaintext: 01001000 (H)
Key: 00110011
────────
Ciphertext: 01111011
Ciphertext: 01111011
Key: 00110011
────────
Plaintext: 01001000 (H) ← recovered!
Quick Reference
Decimal Binary Hex
0 00000000 0x00
10 00001010 0x0A
16 00010000 0x10
32 00100000 0x20
64 01000000 0x40
128 10000000 0x80
255 11111111 0xFF
Computers only understand 0 and 1. Every file, network packet, and password is ultimately stored as binary. Understanding binary lets you read raw memory, shellcode, and XOR operations.
42 ÷ 2 = 21 remainder 0
21 ÷ 2 = 10 remainder 1
10→5 r0 · 5→2 r1 · 2→1 r0 · 1→0 r1
101010 → pad to 8 bits → 00101010
What is the decimal value of binary 11111111?
How many bits are in one byte?
Hexadecimal (base 16) uses digits 0–9 and letters A–F. One hex digit represents exactly 4 bits, so two hex digits = one byte. You'll see hex everywhere in security.
| Decimal | Binary | Hex | Decimal | Binary | Hex |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 4 | 0100 | 4 | 10 | 1010 | A |
| 7 | 0111 | 7 | 15 | 1111 | F |
What is 0xFF in decimal?
How many hex digits represent one byte?
XOR (⊕) is the most important bitwise operation in security — it's used in encryption, hashing, and shellcode obfuscation.
| A | B | A XOR B | AND | OR |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 |
What is 0b1010 XOR 0b1010?
Why is XOR used in simple encryption?
💪 Exercises & Challenges
Number Systems Quiz
Test your ability to convert between number systems and apply binary concepts.
Decode the Hidden Message
Use ASCII to decode a message encoded as decimal numbers.
Process Exploration
## Explore Running Processes ```bash # List all processes ps aux | head -20 # Interactive process viewer top # q to quit # or: htop (install: sudo apt install htop) # Find specific process
Find the Hidden Process
Run `ps aux | grep -v grep | grep python` on your system. If no python process is running, start one: ```bash python3 -c "import time; time.sleep(30)" & ``` Find its PID and submit: `FLAG{found_it}`