2.2 Hexadecimal & ASCII
Key Takeaways
- Hexadecimal is base-16: digits 0–9 and A–F; each hex digit is exactly one nibble (4 bits)
- Convert binary↔hex by grouping bits in fours; convert hex↔decimal via place values 16¹ and 16⁰ (and higher powers for longer values)
- ASCII maps characters to numeric codes: space=32, digit '0'=48, uppercase 'A'=65, lowercase 'a'=97
- Cyber tooling often shows bytes in hex (0x4A, \x41); reading those dumps requires fluent nibble grouping
- Exam traps: confusing ASCII letter codes with hex digit letters; forgetting that '0' is 48 decimal, not zero
Binary is precise but verbose. Hexadecimal (hex) compresses bit patterns into a human-readable form that cyber analysts, packet dumps, and crypto libraries use constantly. ASCII then maps those byte values to printable characters. Together, hex and ASCII let you read what a raw byte stream "means" on the Cyber Test and on the job.
Hexadecimal Basics
Hex is base-16. Digits run 0–9, then A–F (or a–f) for values 10–15. Prefixes like 0x or suffixes like h mark hex in many notations (0xFF, FFh).
| Hex digit | Decimal | Binary (nibble) |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Critical rule: one hex digit ↔ exactly 4 bits (one nibble). Two hex digits ↔ one byte (8 bits). That is why MAC addresses, IPv6 hextets, and hash digests are written in hex — they map cleanly onto bit width.
Binary ↔ Hex via Nibble Grouping
Binary to hex
- Pad the bit string on the left with zeros until the length is a multiple of 4.
- Split into nibbles from the right (or left after padding — same groups).
- Replace each nibble with its hex digit from the table.
Worked example: Convert 11010110₂ to hex.
- Groups:
11010110 1101= 13 = D;0110= 6 → 0xD6
Worked example: Convert 10101111001₂ to hex.
- Pad to 12 bits:
0101 0111 1001 - 5, 7, 9 → 0x579
Hex to binary
Expand each hex digit into its 4-bit pattern. Do not drop leading zeros inside a nibble — 0x0A is 00001010, not 1010 alone if you need a full byte.
Worked example: 0x3C → 0011 1100 → 00111100₂ = 60₁₀.
Hex to decimal (short values)
For two-digit hex XY: value = (X × 16) + Y.
0xA5= (10 × 16) + 5 = 160 + 5 = 1650xFF= (15 × 16) + 15 = 255 (full unsigned byte — same landmark as11111111₂)
For three digits XYZ: (X × 256) + (Y × 16) + Z, since 16² = 256.
Why Cyber Candidates Live in Hex
- Packet and memory dumps show bytes as hex pairs (
4F 70 65 6E). - IPv6 addresses use hex hextets; nibble fluency transfers.
- Crypto digests (MD5, SHA-256) are printed as hex strings — each two characters is one byte of the hash.
- Bitwise masks in config files often appear as
0xFF00rather than long binary.
If a dump shows 0x41, you should instantly think both "65 decimal" and "ASCII 'A'" — that dual reading is the point of this section.
ASCII: Characters as Numbers
ASCII (American Standard Code for Information Interchange) assigns integers to characters so text can travel as bytes. Classic ASCII uses 7 bits (0–127); in practice you see it embedded in 8-bit bytes (high bit often 0).
High-value code points to memorize
| Character | Decimal | Hex | Binary (8-bit) | Notes |
|---|---|---|---|---|
| space | 32 | 0x20 | 00100000 | Word separator; common in parsers |
| '0' | 48 | 0x30 | 00110000 | Digit zero — not numeric value 0 |
| '1' | 49 | 0x31 | 00110001 | Digits ascend: '0'+n |
| '9' | 57 | 0x39 | 00111001 | End of digit range |
| 'A' | 65 | 0x41 | 01000001 | Uppercase start |
| 'Z' | 90 | 0x5A | 01011010 | Uppercase end |
| 'a' | 97 | 0x61 | 01100001 | Lowercase = uppercase + 32 |
| 'z' | 122 | 0x7A | 01111010 | Lowercase end |
Patterns that save time
- Digits:
'0'–'9'are 48–57. The character'7'has code 48 + 7 = 55, not 7. - Case shift: lowercase = uppercase + 32. Flipping bit 5 (value 32) often toggles case in ASCII — a bitwise intuition you will reuse in section 2.3.
- Letters:
'A'= 65,'B'= 66, … so'C'= 67 = 0x43.
Worked examples
- What character is ASCII 65? → 'A'.
- Byte
0x30in a text stream? → character '0' (digit zero). - Hex dump
48 69→ decimal 72, 105 → 'H', 'i' → string"Hi". - Difference between
'a'and'A': 97 − 65 = 32 (one bit in the byte).
Exam Traps
- Hex letters vs ASCII letters: Hex digit
Ameans ten. ASCII'A'means code 65. Context decides. - Character
'0'vs value 0:'0'is 48. Numeric zero as a byte is0x00(NUL), not the digit character. - Nibble mis-grouping: Grouping
11010110as11010110instead of11010110produces wrong hex. - Case in hex digits:
0xafequals0xAF; case of hex letters does not change value. Case of ASCII letters does. - Seven-bit vs eight-bit: Printable ASCII fits in 0–127; a byte
0xC2is outside classic printable ASCII and often signals UTF-8 or extended sets — do not force it into'A'–'Z'logic.
Study drill
Convert random bytes both ways: binary ↔ hex ↔ decimal, then ask "if this were ASCII, what character?" That triple fluency is what CT-style items reward.
Networking and crypto cameo
An Ethernet MAC might read 00:1A:2B:3C:4D:5E — each pair is a hex byte. A truncated SHA-256 preview e3b0c442… is also hex. You are not asked to compute hashes here; you are asked to read the encoding. Hex and ASCII are the shared language of those displays.
What is the hexadecimal representation of the binary value 10101111?
Which ASCII decimal code corresponds to the character 'A'?
A hex dump shows the byte 0x30. If interpreted as ASCII, which character is it?
What is the decimal value of hex 0xC8?