Number Representation

Loading concept...

πŸ”’ 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:

  1. Divide by 2
  2. Write down the remainder (0 or 1)
  3. Repeat until you get 0
  4. 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:

  1. Write the positive number in binary
  2. Flip all bits (0β†’1, 1β†’0)
  3. 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! πŸŽ‰

Loading story...

No Story Available

This concept doesn't have a story yet.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

Interactive Preview

Interactive - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Interactive Content

This concept doesn't have interactive content yet.

Cheatsheet Preview

Cheatsheet - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Cheatsheet Available

This concept doesn't have a cheatsheet yet.

Quiz Preview

Quiz - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Quiz Available

This concept doesn't have a quiz yet.