๐ข Why Understand Number Systems?
Computers don't understand numbers like we do. They only work with 0s and 1s (electricity on/off). In RE, you'll see numbers in base 16 (hexadecimal) all the time - in memory addresses, Assembly code, and analysis tools.
๐ Base 10 (Decimal) - What We Know
The number of different symbols in a number system. Base 10 = 10 digits (0-9).
In the decimal system, each position is worth 10ร the previous one:
The number 1234 in decimal:
1 2 3 4
โ โ โ โ
1ร10ยณ + 2ร10ยฒ + 3ร10ยน + 4ร10โฐ
1000 + 200 + 30 + 4 = 1234
๐พ Base 2 (Binary) - The Computer's Language
A base-2 number system. Only 2 digits: 0 and 1. Each digit is called a Bit.
The smallest unit of information in a computer. Can be 0 or 1.
A group of 8 bits. Can represent values from 0 to 255.
Converting Binary to Decimal
Each position in binary is worth 2ร the previous one (right to left):
Binary 11010110 in decimal:
128 + 64 + 16 + 4 + 2 = 214
Converting Decimal to Binary
Divide by 2 repeatedly and note the remainder:
13 รท 2 = 6 remainder 1 โ
6 รท 2 = 3 remainder 0 โ
3 รท 2 = 1 remainder 1 โ Read from bottom to top
1 รท 2 = 0 remainder 1 โ
Result: 13 = 1101 in binary
๐ท Base 16 (Hexadecimal) - The Language of RE
A base-16 number system. Uses 16 symbols: 0-9 and A-F.
Common notation: 0x prefix (e.g., 0xFF) or h suffix.
Why is hexadecimal so common in RE?
- Compact: 1 hex digit = exactly 4 bits
- 2 hex digits = exactly 1 byte (very convenient!)
- Easy to convert to/from binary
Important Conversion Table
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
To convert between binary and hex: split binary into groups of 4 and convert each group.
1101 0110 โ D 6 โ 0xD6
A typical Windows 32-bit address:
0x00401000
00 40 10 00 (4 bytes)
โ โ โ โ
0 64 16 0 (decimal value of each byte)
๐ Text Representation - ASCII
A standard for representing characters as numbers. Each character is represented by a number between 0-127.
For example: A = 65, a = 97, 0 = 48.
| Char | Decimal | Hex | Char | Decimal | Hex |
|---|---|---|---|---|---|
| A | 65 | 0x41 | a | 97 | 0x61 |
| B | 66 | 0x42 | b | 98 | 0x62 |
| Z | 90 | 0x5A | z | 122 | 0x7A |
| 0 | 48 | 0x30 | 9 | 57 | 0x39 |
| Space | 32 | 0x20 | Enter | 13 | 0x0D |
H e l l o (characters)
72 101 108 108 111 (decimal)
0x48 0x65 0x6C 0x6C 0x6F (hex)
โ Negative Numbers
A method for representing negative numbers in binary. The leftmost bit (MSB) indicates the sign: 0 = positive, 1 = negative.
In one byte (8 bits):
- Unsigned: 0 to 255
- Signed: -128 to +127
To get -5:
1. Write 5 in binary: 0000 0101
2. Flip all bits: 1111 1010
3. Add 1: 1111 1011
1111 1011 = 0xFB = -5 (signed)
= 251 (unsigned)
๐ Units of Measurement
| Unit | Size | Range (unsigned) |
|---|---|---|
| Bit | 1 bit | 0-1 |
| Nibble | 4 bits | 0-15 (0x0-0xF) |
| Byte | 8 bits | 0-255 (0x00-0xFF) |
| Word | 16 bits (2 bytes) | 0-65,535 (0x0000-0xFFFF) |
| DWORD | 32 bits (4 bytes) | 0-4,294,967,295 |
| QWORD | 64 bits (8 bytes) | 0-18.4ร10ยนโธ |
DWORD = Double Word (very common in 32-bit)
QWORD = Quad Word (common in 64-bit)
You'll see these terms a lot in IDA and Assembly!
๐ Chapter Summary
- Binary (base 2) - computer's language, 0s and 1s
- Hexadecimal (base 16) - common in RE, easy to convert
- 1 byte = 8 bits = 2 hex digits
- ASCII - character representation as numbers
- Two's Complement - negative numbers
- Remember the 0-F table!