Computer Fundamentals: Hexadecimal System
Hexadecimal (Hex) is a base-16 number system. It uses sixteen distinct symbols: the numbers 0-9 and the letters A-F.
It is the standard way to represent binary data in computing, used in memory addresses, IP addresses, and styling colors.
1. Why use Hexadecimal?
Computers operate in Binary (Base-2), using only 0s and 1s. However, binary strings are too long and difficult for humans to read.
- Binary:
1111 1111(Hard to read quickly) - Decimal:
255(Hard to convert back to bits mentally) - Hex:
FF(Concise and maps directly to bits)
Key Concept: One Hexadecimal digit represents exactly 4 bits (a Nibble) of binary data. Two Hex digits make 1 Byte (8 bits).
2. Notation
In programming languages like C, C++, and Python, a prefix is used to indicate a Hex number.
0x: Standard prefix (e.g.,0xA5,0xFF)#: Used in HTML/CSS colors (e.g.,#FF0000)
3. Conversion Tables
① Decimal to Hexadecimal
Comparing our everyday counting system (Base-10) with Hex (Base-16).
| Decimal (Base-10) | Hexadecimal (Base-16) | Note |
|---|---|---|
| 0 | 0 | |
| 1 | 1 | |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | A | Start of letters |
| 11 | B | |
| 12 | C | |
| 13 | D | |
| 14 | E | |
| 15 | F | Max value of 4 bits |
② Hexadecimal to Binary - ⭐ Essential for Hardware
This mapping is crucial for bitwise operations in embedded systems.
| Hex (Base-16) | Binary (Base-2) | Decimal Value |
|---|---|---|
| 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 |
| A | 1010 |
10 |
| B | 1011 |
11 |
| C | 1100 |
12 |
| D | 1101 |
13 |
| E | 1110 |
14 |
| F | 1111 |
15 |
Example: Convert
0xB3to Binary?B(11) ->10113(3) ->0011Result:1011 0011
1 Byte (2 Hex Digits) to Decimal
A Byte consists of 2 Hexadecimal digits. It ranges from 00 to FF.
Formula: (High Digit × 16) + Low Digit
Example:
0x2A= (2 × 16) + 10 = 42
1. Key Milestones Table
Commonly used values and limits.
| Hexadecimal | Decimal | Note |
|---|---|---|
| 00 | 0 | Minimum Value |
| 01 | 1 | |
| 0A | 10 | |
| 0F | 15 | |
| 10 | 16 | |
| 1F | 31 | |
| 20 | 32 | Space char in ASCII |
| 32 | 50 | |
| 40 | 64 | Power of 2 ($2^6$) |
| 64 | 100 | Decimal 100 |
| 7F | 127 | Max Signed Integer (7-bit) |
| 80 | 128 | Most Significant Bit (MSB) is 1 |
| A0 | 160 | |
| C8 | 200 | Decimal 200 |
| FF | 255 | Maximum Value (All bits 1) |
2. High Nibble Lookup Table (for Mental Math)
Use this to quickly calculate the value based on the first digit.
| High Nibble (First Digit) | Base Value ($N \times 16$) |
|---|---|
| 0_ | 0 |
| 1_ | 16 |
| 2_ | 32 |
| 3_ | 48 |
| 4_ | 64 |
| 5_ | 80 |
| 6_ | 96 |
| 7_ | 112 |
| 8_ | 128 |
| 9_ | 144 |
| A_ | 160 |
| B_ | 176 |
| C_ | 192 |
| D_ | 208 |
| E_ | 224 |
| F_ | 240 |
How to use: To convert
0xC2: 1. Look upC_in the table -> 192. 2. Add the second digit2. 3. 192 + 2 = 194.