IT231 Foundation Of Information Technology

Foundation Of Information TechnologyUnit 28 min read

Data Representation & Number Systems: Binary, Hex, ASCII, and Memory

Unit 2 of Foundation Of Information Technology: explores how computers store and process data using binary, hexadecimal, and ASCII codes, memory hierarchy, and real-world applications like eSewa transactions and Daraz inventory systems.

TAKEAWAYS:

  • Computers use binary (base-2) to represent all data, including text, images, and numbers.
  • Hexadecimal (base-16) simplifies binary representation for humans and software.
  • ASCII and Unicode encode characters (e.g., letters, symbols) into binary for storage and transmission.
  • Memory hierarchy (registers → RAM → SSD → HDD) balances speed and cost in computer systems.
  • Data conversion (binary ↔ decimal ↔ hex) is essential for debugging and software development.
  • Real-world examples like eSewa’s transaction codes and Daraz’s inventory tracking rely on these concepts.

1. Introduction to Data Representation

Computers cannot process human-readable data (e.g., text, images) directly. Instead, they convert everything into binary (0s and 1s). This section covers how data is encoded and represented internally.

Why Binary?

  • Simplicity: Electronic circuits (transistors) naturally switch between two states: ON (1) and OFF (0).
  • Universality: All data—numbers, text, images—is stored as binary.
  • Efficiency: Binary operations (AND, OR, NOT) are fast and hardware-friendly.

2. Number Systems

Computers use multiple number systems to represent data. The key systems are:

  • Decimal (Base-10): Human default (digits 0–9).
  • Binary (Base-2): Computer default (digits 0–1).
  • Hexadecimal (Base-16): Shorthand for binary (digits 0–9, A–F).
  • Octal (Base-8): Rarely used today, but historically important.

Conversion Between Number Systems

Conversion Formula/Method
Decimal → Binary Divide by 2, record remainders (LSB to MSB).
Binary → Decimal Sum of each bit × 2^n (where n is its position, starting from 0).
Decimal → Hex Divide by 16, use A=10, B=11, ..., F=15.
Hex → Binary Replace each hex digit with its 4-bit binary equivalent.

Example: Convert 13 (decimal) to binary and hex.

  • Decimal to Binary:
    13 ÷ 2 = 6  (remainder 1)
     6 ÷ 2 = 3  (remainder 0)
     3 ÷ 2 = 1  (remainder 1)
     1 ÷ 2 = 0  (remainder 1)
    
    Reading remainders bottom-up: 1101 (binary).
  • Decimal to Hex: 13 ÷ 16 = 0 (remainder D). So, 13 (decimal) = D (hex).

Mermaid Diagram: Conversion Flowchart

flowchart TD
    A["Decimal"] -->|"Divide by 2"| B["Binary"]
    A -->|"Divide by 16"| C["Hex"]
    B --> D["Check remainders"]
    C --> E["Use A-F for 10-15"]

3. Binary Arithmetic

Computers perform arithmetic using binary logic gates. Key operations:

  • Addition: Follows rules like 0+0=0, 1+1=10 (carry over).
  • Subtraction: Uses 2’s complement for negative numbers.
  • Multiplication/Division: Extends binary addition/subtraction.

Example: Binary Addition (1011 + 1101)

  1011
+ 1101
-------
 10100  (Result: `20` in decimal)

4. Data Representation: ASCII and Unicode

Text is stored as binary using character encoding schemes:

  • ASCII (American Standard Code for Information Interchange): 7-bit (128 characters), covers basic English letters, symbols, and numbers.
  • Unicode (UTF-8/UTF-16): Extends ASCII to support global languages (e.g., Nepali, Chinese, Arabic).
Character ASCII (Decimal) ASCII (Binary) Unicode (UTF-8)
A 65 01000001 01000001
é - - 01100011 01101001
नेपाली - - Multi-byte

Mermaid Diagram: ASCII Table Snippet

Why Unicode?

  • eSewa/Khalti: Use Unicode to display Nepali characters in transaction confirmations.
  • WhatsApp/YouTube: Unicode ensures messages/videos render correctly across languages.

5. Memory Hierarchy and Data Storage

Computers use a memory hierarchy to balance speed and cost:

  1. Registers (Fastest, smallest, e.g., CPU registers like AX, BX).
  2. Cache Memory (L1, L2, L3: ~MBs, faster than RAM).
  3. RAM (Random Access Memory) (GBs, volatile, holds running programs).
  4. SSD (Solid State Drive) (GBs–TB, non-volatile, faster than HDD).
  5. HDD (Hard Disk Drive) (TB, slowest, cheapest).

computer memory hierarchy diagramLayers from registers to HDD with speed/cost trade-offs (Image: ComputerMemoryHierarchy.png: User:Danlash at en.wikipedia.or, Public domain, via Wikimedia Commons)

Example: Daraz’s Inventory System

  • RAM: Stores real-time stock levels of products (e.g., 100 units of "Nepalgunj Rice").
  • SSD: Logs historical sales data for analytics.
  • HDD: Archives old inventory reports.

6. Real-World Applications

## In the Real World

  1. eSewa/Khalti:

    • Idea: Hexadecimal encoding of transaction IDs (e.g., A1B2C3D4) for compact storage in databases.
    • How: Transaction IDs are often stored as hex to save space and enable quick binary processing.
  2. Daraz Order Processing:

    • Idea: Binary flags to mark order status (e.g., 101 = "Processing," 110 = "Shipped").
    • How: Logical operations on binary flags automate workflows (e.g., AND to check if an order is paid and shipped).
  3. NTC/Ncell Network Routing:

    • Idea: IP addresses (e.g., 192.168.1.1) are stored in binary internally but represented in decimal for humans.
    • How: Routers use binary logic to forward data packets based on IP prefixes.

Worked Example: Calculating Loan Interest (Banking) A bank uses binary arithmetic to compute interest:

  • Suppose a loan amount is ₹50,000 (stored as binary: 01100011 00101000 00000000 00000000).
  • Interest rate: 5% (stored as 00000101 in binary).
  • Calculation:
    1. Convert 50,000 to binary (as above).
    2. Multiply by 5% using binary multiplication.
    3. Result: ₹2,500 (interest), stored back in binary.

7. Advantages and Limitations

Feature Advantages Limitations
Binary Representation Universal, hardware-efficient, fast operations Cumbersome for humans to read/write.
Hexadecimal Compact (4 bits per hex digit), easier debugging Still abstract for non-technical users.
ASCII/Unicode Standardized, supports global languages Unicode tables are large (e.g., UTF-8 uses 1–4 bytes per character).
Memory Hierarchy Balances cost and performance Slower access to lower levels (HDD).

Exam Tip

  • Focus on conversions: Practice decimal ↔ binary ↔ hex (e.g., 255 → FF → 11111111).
  • ASCII/Unicode: Know key codes (e.g., 65 = A, 97 = a) and why Unicode is needed for multilingual apps.
  • Memory hierarchy: Compare speed/cost trade-offs (e.g., "Why does a CPU use cache?").
  • Real-world links: Relate to apps like eSewa (hex IDs), Daraz (binary flags), or NTC (IP routing).
  • Common mistakes:
    • Confusing ASCII (7-bit) and Unicode (variable-bit).
    • Forgetting 2’s complement for negative binary numbers.
    • Misaligning bits during conversions (e.g., 101 vs 0101).

Sample Exam Question: "Explain how a computer stores the character ‘ने’ in binary using Unicode. Why is ASCII insufficient for Nepali text?" Answer Structure:

  1. Unicode uses UTF-8 (multi-byte encoding).
  2. ‘ने’ is encoded as 01001110 01101001 01101110 (UTF-8 bytes).
  3. ASCII lacks Nepali characters (only covers 128 symbols).

Mermaid Diagram: ASCII vs Unicode

mindmap
  root((Character Encoding))
    ASCII
      only 128 characters
      limited to English
    Unicode
      UTF-8/UTF-16
      supports global languages
      multi-byte per character

Based on the TU BITM syllabus for Foundation Of Information Technology (IT231), unit 2.

Discussion

Loading…