P
NUMBER SYSTEMS & HEX β DECIMAL
number systems and specifically how to convert between hexadecimal and decimal.
In computing and networking, we use different types of number systems. A number system is simply a way to represent numbers.
In everyday life, we use the decimal system, which is base 10. That means it uses digits from 0 to 9.
In computing, there are three other very important number systems:
- Binary (base 2)
- Octal (base 8)
- Hexadecimal (base 16)
Hexadecimal is a positional number system with base 16. It uses 16 symbols:
- 0 to 9
- A, B, C, D, E, F
The letters represent values:
```text id="hexmap"
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
Each position in a hexadecimal number represents a power of 16.
For example, a two-digit hex number has positions:
```text id="pos16"
16^1 16^0
π§ͺ EXAMPLE 1 β HEX β DECIMAL
Convert B6 to decimal.
Step 1: Write positional values.
```text id="ex1pos"
B 6
16^1 16^0
Step 2: Convert hex to decimal.
```text id="ex1conv"
B = 11
6 = 6
Step 3: Multiply by powers.
```text id="ex1math"
11 Γ 16 = 176
6 Γ 1 = 6
Step 4: Add results.
```text id="ex1sum"
176 + 6 = 182
So, B6 in hexadecimal equals 182 in decimal.
π§ͺ EXAMPLE 2 β HEX β DECIMAL
Convert A59C to decimal.
Step 1: Positions:
```text id="ex2pos"
A 5 9 C
16^3 16^2 16^1 16^0
Step 2: Convert values:
```text id="ex2conv"
A = 10
5 = 5
9 = 9
C = 12
Step 3: Multiply:
```text id="ex2math"
10 Γ 16^3 = 40960
5 Γ 16^2 = 1280
9 Γ 16 = 144
12 Γ 1 = 12
Step 4: Add:
```text id="ex2sum"
40960 + 1280 + 144 + 12 = 42396
So, A59C equals 42396 in decimal.
π DECIMAL β HEXADECIMAL
Now we do the reverse.
We convert decimal to hexadecimal using division by 16.
π§ͺ EXAMPLE 3 β DECIMAL β HEX
Convert 256 to hexadecimal.
Step-by-step:
```text id="ex3steps"
256 Γ· 16 = 16 remainder 0
16 Γ· 16 = 1 remainder 0
1 Γ· 16 = 0 remainder 1
Now write remainders from bottom to top:
```text id="ex3result"
100
So:
256 = 100 (hex)
π§ͺ EXAMPLE 4 β DECIMAL β HEX
Convert 7562 to hexadecimal.
Step-by-step:
```text id="ex4steps"
7562 Γ· 16 = 472 remainder 10
472 Γ· 16 = 29 remainder 8
29 Γ· 16 = 1 remainder 13
1 Γ· 16 = 0 remainder 1
Convert remainders:
```text id="ex4conv"
10 = A
8 = 8
13 = D
1 = 1
Write bottom to top:
```text id="ex4result"
1D8A
So:
7562 = 1D8A (hex)
---
# π§ IMPORTANT RULES
### Hex β Decimal
π Multiply each digit by powers of 16 and add
### Decimal β Hex
π Divide by 16 repeatedly and collect remainders
βHexadecimal is base 16, which means each position represents powers of 16. To convert from hex to decimal, we multiply each digit by its positional value and add the results. To convert from decimal to hex, we repeatedly divide by 16 and track the remainders.β
---
# π§ WHY THIS IS IMPORTANT (NETWORKING)
In networking:
* MAC addresses use hexadecimal
* IPv6 uses hexadecimal
* Memory addresses use hexadecimal
---
# π» PRACTICE
### Convert to decimal:
```text id="practice1"
1A
2F
FF
Convert to hex:
```text id="practice2"
100
500
1024
---
# π INTERVIEW ANSWER
βHexadecimal is a base-16 number system commonly used in computing. Conversion from hex to decimal involves multiplying digits by powers of 16, while conversion from decimal to hex uses repeated division by 16.β
---
# π― FINAL SUMMARY
* Decimal = base 10
* Hex = base 16
* Hex uses 0β9 and AβF
* Use multiplication for hex β decimal
* Use division for decimal β hex
Everything in networking is based on **bits β bytes β IP**
---
## What is a BIT?
π A **bit** is the smallest unit of data
```text
bit = 0 or 1
- 0 = OFF
- 1 = ON
What is a BYTE?
π A byte = 8 bits
1 byte = 8 bits
Example:
10101010 β 1 byte
What is an OCTET?
π An octet = 8 bits (same as byte)
In networking, we say:
- byte β general computing
- octet β networking (IP addresses)
π― KEY IDEA
1 octet = 8 bits = numbers from 0 to 255
π 2. Why 0β255?
Because:
2^8 = 256
π So:
0 to 255 = 256 values
π 3. Structure of IP Address
Example:
192.168.1.10
This has 4 octets:
[192] [168] [1] [10]
Each one = 8 bits
Total:
4 Γ 8 = 32 bits
π 4. The βBOX METHODβ (This is what you asked)
This is how you convert numbers like 192 into bits
Step 1 β Draw boxes
Each octet has 8 boxes (bits)
128 64 32 16 8 4 2 1
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
π These numbers are powers of 2
π 5. Example: Convert 192
We need to make 192 using these numbers
Step-by-step:
192 - 128 = 64 β use 128 β put 1
64 - 64 = 0 β use 64 β put 1
Remaining = 0 β rest are 0
Final boxes:
128 64 32 16 8 4 2 1
1 1 0 0 0 0 0 0
Final answer:
192 = 11000000
π 6. Example: Convert 168
Step-by-step:
168 - 128 = 40 β 1
40 - 32 = 8 β 1
8 - 8 = 0 β 1
Boxes:
128 64 32 16 8 4 2 1
1 0 1 0 1 0 0 0
Final:
168 = 10101000
π 7. Example: Convert 1
00000001
π 8. Example: Convert 0
00000000
π 9. Full IP in Binary
192.168.1.10 =
11000000.10101000.00000001.00001010
π 10. VERY SIMPLE MEMORY TRICK
π Think:
Big numbers β left side
Small numbers β right side
π 11. Shortcut Table (Memorize This)
| Decimal | Binary |
|---|---|
| 128 | 10000000 |
| 192 | 11000000 |
| 224 | 11100000 |
| 240 | 11110000 |
| 248 | 11111000 |
| 252 | 11111100 |
| 255 | 11111111 |
π These are used in subnet masks
π 12. Why This Matters
You need this to understand:
- subnet mask
- network vs host
- AWS VPC
- CIDR
π FINAL SUMMARY
π bit = 0 or 1
π 8 bits = 1 byte = 1 octet
π octet = 0β255
π IP = 4 octets = 32 bits
π boxes = powers of 2
π fill with 1s to reach number












