Binary & Number Systems

Convert between decimal, binary, and hex — essential for reading shellcode, network packets, and hashes.

Easy 35m 3 tasks
Prerequisites: The Security Mindset

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.

Decimal 42 in Binary
Decimal → Binary Conversion
1
Divide by 2

42 ÷ 2 = 21 remainder 0

2
Divide again

21 ÷ 2 = 10 remainder 1

3
Continue

10→5 r0 · 5→2 r1 · 2→1 r0 · 1→0 r1

4
Read remainders upward

101010 → pad to 8 bits → 00101010

# Python: quick number base conversions bin(42) # '0b101010' hex(42) # '0x2a' int('101010', 2) # 42 (binary → decimal) int('2a', 16) # 42 (hex → decimal)
✦ Answer the questions to complete this task

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.

DecimalBinaryHexDecimalBinaryHex
000000810008
100011910019
401004101010A
701117151111F
Where you'll see hex in security
File magic bytes — 89 50 4E 47 = PNG header
SHA-256 hash — 64 hex chars = 32 bytes
Memory addresses — 0x7ffeed3a0 (x86-64 stack)
XOR shellcode — \xeb\x2a = JMP +42
IP in hex — C0 A8 01 01 = 192.168.1.1
# Hex in Python bytes.fromhex('89504e47') # b'\x89PNG' 'hello'.encode().hex() # '68656c6c6f' # xxd — dump file as hex xxd /etc/passwd | head -3
✦ Answer the questions to complete this task

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.

ABA XOR BANDOR
00000
01101
10101
11011
XOR Key Properties
Self-inverse
A ⊕ B ⊕ B = A
XOR same key twice → original
Encryption use
plaintext ⊕ key = cipher
Used in AES, RC4, OTP
# XOR in Python 0b1010 ^ 0b1100 # = 0b0110 (6) # Simple XOR encryption key = 0x42 plaintext = b'hello' ciphertext = bytes([b ^ key for b in plaintext]) # b'\x2a\x27\x2e\x2e\x2d' # Decrypt: XOR again with same key bytes([b ^ key for b in ciphertext]) # b'hello'
⚠ Security: Malware commonly XOR-encodes strings with a single byte key to evade signature detection. AV analysts XOR-decode the payload to read it.
✦ Answer the questions to complete this task

What is 0b1010 XOR 0b1010?

Why is XOR used in simple encryption?

💪 Exercises & Challenges

📝 MCQ Easy +20 XP

Number Systems Quiz

Test your ability to convert between number systems and apply binary concepts.

Start →
🚩 Challenge Easy +20 XP

Decode the Hidden Message

Use ASCII to decode a message encoded as decimal numbers.

Start →
⚙️ Practical Easy +25 XP

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

Start →
🚩 Challenge Easy +50 XP

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}`

Start →