π’ Number Systems: How Computers Count!
Imagine you only had two fingers instead of ten. How would you count? Thatβs exactly how computers work!
π The Big Picture
Think of numbers like different languages. We humans speak βDecimalβ (0-9), but computers only understand βBinaryβ (0-1). Just like translating between English and Spanish, we can translate numbers between these systems!
graph TD A[Human Numbers<br/>0, 1, 2... 9] -->|Translate| B[Computer Numbers<br/>0, 1] B -->|Translate| A
π Chapter 1: Binary - The Computerβs Language
π― What is Binary?
Binary is counting with just two symbols: 0 and 1.
Think of it like a light switch - itβs either OFF (0) or ON (1). Thatβs it! Computers are made of billions of tiny switches.
π¦ The Light Switch Story
Imagine you have a row of light switches. Each switch can be:
- OFF = 0
- ON = 1
| Switches | What it means |
|---|---|
0 |
Zero (all off) |
1 |
One (first switch on) |
10 |
Two (second switch on, first off) |
11 |
Three (both on) |
100 |
Four |
π‘ Simple Example
In decimal (our system): 5 means βfive thingsβ
In binary: 101 also means βfive thingsβ!
How? Each position has a value that doubles:
Position: 4 2 1
Binary: 1 0 1
β β β
4 + 0 + 1 = 5
π Chapter 2: Number System Conversions
πͺ The Magic Translation Game
Converting numbers is like being a translator between number languages!
Decimal β Binary (How to translate TO computer)
The Division Game:
- Divide by 2
- Write down the remainder (0 or 1)
- Repeat until you get 0
- Read remainders backwards!
Example: Convert 13 to binary
13 Γ· 2 = 6 remainder 1
6 Γ· 2 = 3 remainder 0
3 Γ· 2 = 1 remainder 1
1 Γ· 2 = 0 remainder 1
Read backwards: 1101
β 13 in decimal = 1101 in binary
Binary β Decimal (How to translate FROM computer)
The Doubling Game:
- Start from the right
- Each position doubles: 1, 2, 4, 8, 16, 32β¦
Example: Convert 1101 to decimal
Binary: 1 1 0 1
Value: 8 4 2 1
β β β β
8 + 4 + 0 + 1 = 13
π¨ Chapter 3: Hexadecimal - The Shortcut System
π Why Hex?
Binary numbers get LONG! Writing 11111111 is tiring.
Hexadecimal (hex) uses 16 symbols: 0-9 and A-F
| Decimal | Binary | Hex |
|---|---|---|
| 0-9 | 0000-1001 | 0-9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
π― The Color Connection
Ever seen color codes like #FF0000? Thatβs hex!
- FF = 255 (maximum red)
- 00 = 0 (no green)
- 00 = 0 (no blue)
Result: Bright red! π΄
π Conversion Example
Hex F3 to decimal:
F = 15, 3 = 3
F3 = (15 Γ 16) + 3 = 240 + 3 = 243
π¦ Chapter 4: Bits, Bytes, and Word Size
π§± The Building Blocks
Think of computer memory like LEGO bricks:
| Unit | Size | Like⦠|
|---|---|---|
| Bit | 1 switch (0 or 1) | A single LEGO dot |
| Byte | 8 bits | A LEGO brick |
| Word | 32 or 64 bits | A LEGO section |
π Real Examples
- 1 bit = Yes or No
- 1 byte = One letter (like βAβ)
- 1 kilobyte (KB) = A short email
- 1 megabyte (MB) = A photo
- 1 gigabyte (GB) = A movie
π’ Word Size
A computerβs word size is how many bits it processes at once.
- 32-bit computer: Handles 32 bits together
- 64-bit computer: Handles 64 bits together (faster!)
βοΈ Chapter 5: Character Encoding
π How Computers Store Letters
Computers only know numbers! So every letter has a secret number code.
π€ ASCII - The Original Code
American Standard Code for Information Interchange
| Character | Number | Binary |
|---|---|---|
| A | 65 | 01000001 |
| B | 66 | 01000010 |
| a | 97 | 01100001 |
| 0 | 48 | 00110000 |
| Space | 32 | 00100000 |
π Unicode - The World Code
ASCII only had 128 characters. Not enough for δΈζ, Ψ§ΩΨΉΨ±Ψ¨ΩΨ©, or emoji! π
Unicode gives EVERY character a number:
- π = U+1F600
- δΈ = U+4E2D
- β€ = U+2764
β Chapter 6: Integer Representation
π Storing Whole Numbers
Integers are whole numbers like -5, 0, 42.
Unsigned integers: Only positive (0 and up)
- 8 bits = 0 to 255
Signed integers: Positive AND negative
- 8 bits = -128 to 127
π― The Range Rule
With n bits, you can store:
- Unsigned: 0 to (2βΏ - 1)
- Signed: -2βΏβ»ΒΉ to (2βΏβ»ΒΉ - 1)
Example with 8 bits:
- Unsigned: 0 to 255
- Signed: -128 to 127
π Chapter 7: Twoβs Complement
π The Negative Number Trick
How do computers store negative numbers? With a clever trick called Twoβs Complement!
πͺ The Magic Recipe
To make a negative number:
- Write the positive number in binary
- Flip all bits (0β1, 1β0)
- Add 1
π Example: Making -5
Step 1: +5 in binary = 00000101
Step 2: Flip bits = 11111010
Step 3: Add 1 = 11111011
-5 = 11111011
β Why This Works
The first bit becomes the sign bit:
- 0 at the start = positive
- 1 at the start = negative
| Binary | Decimal |
|---|---|
| 00000101 | +5 |
| 11111011 | -5 |
| 00000000 | 0 |
| 11111111 | -1 |
π Chapter 8: Floating-Point Numbers
π Numbers with Decimals
How do computers store 3.14 or 0.001?
Floating-point = the decimal βfloatsβ to different positions.
π¬ Scientific Notation for Computers
Remember scientific notation? Like 3.14 Γ 10Β²
Computers use the same idea with binary!
A floating-point number has 3 parts:
ββββββββ¬βββββββββββ¬βββββββββββββββ
β Sign β Exponent β Mantissa β
β +/- β Power β Actual digitsβ
ββββββββ΄βββββββββββ΄βββββββββββββββ
π IEEE 754 Standard
| Type | Bits | Range |
|---|---|---|
| Float | 32 | Β±3.4 Γ 10Β³βΈ |
| Double | 64 | Β±1.8 Γ 10Β³β°βΈ |
β οΈ The Precision Problem
Computers canβt store ALL decimal numbers exactly!
0.1 + 0.2 = 0.30000000000000004
This is normal! Itβs like trying to write 1/3 as a decimal - it goes on forever.
π Chapter 9: Endianness
π Reading Order for Bytes
When a number needs multiple bytes, which byte comes first?
π₯ͺ The Sandwich Analogy
Imagine writing the number 0x12345678:
Big-Endian (Big end first):
Memory: [12] [34] [56] [78]
β Most significant first
Like reading left-to-right!
Little-Endian (Little end first):
Memory: [78] [56] [34] [12]
β Least significant first
Like reading right-to-left!
π₯οΈ Which Computers Use What?
| Endianness | Used By |
|---|---|
| Big-Endian | Network data, some CPUs |
| Little-Endian | Intel, AMD, most PCs |
π― Example
Store 258 (0x0102) in 2 bytes:
Big-Endian: [01] [02]
Little-Endian: [02] [01]
π Quick Summary
graph TD A[Number Systems] --> B[Binary<br/>0s and 1s] A --> C[Hex<br/>0-9, A-F] A --> D[Storage] D --> E[Bits & Bytes] D --> F[Integers] D --> G[Floats] D --> H[Characters] F --> I[Two's Complement] G --> J[IEEE 754] D --> K[Endianness]
π You Did It!
Now you know how computers:
- β Count with just 0s and 1s
- β Store positive AND negative numbers
- β Handle decimal numbers
- β Remember every letter and emoji
- β Organize bytes in memory
Youβre speaking computer now! π