Introduction to Information TechnologyUnit 310 min read
Data Representation & Number Systems: Binary, Hex, Octal, Fixed-Point & Real-World Apps
Unit 3 of Introduction to Information Technology covers how computers store and process data using binary, hexadecimal, octal, and fixed-point number systems, with real-world applications in banking, e-commerce, and IoT devices like eSewa and Ncell billing systems.
TAKEAWAYS:
- Computers use binary (base-2), hexadecimal (base-16), and octal (base-8) to represent data efficiently, with conversions between them following strict mathematical rules.
- Fixed-point numbers store integers and fractions separately, critical for financial calculations (e.g., loan interest in banks) and sensor data in IoT.
- Signed number representations (e.g., 2’s complement) enable computers to handle negative values without extra hardware, used in all modern processors.
- Real-world systems (e.g., WhatsApp encryption, NEPSE stock prices, Pathao ride queues) rely on these representations for speed and accuracy.
- Exam focus: Conversion problems (decimal ↔ binary/hex/octal), fixed-point arithmetic, and identifying where each system is used in technology.
Core Concepts: Why Computers Use Binary, Hex, and Octal
Computers process data as electrical signals (on/off states), making binary (base-2) the natural language for machines. However, humans prefer decimal (base-10). To bridge this gap, computers use hexadecimal (base-16) and octal (base-8) for compact representation and easier debugging.
1. Binary Number System (Base-2)
Binary uses two digits (0 and 1) to represent all data. Each digit is a bit (binary digit), and groups of 8 bits form a byte (the smallest addressable unit in memory).
graph LR
A["Bit (0 or 1)"] --> B["Nibble (4 bits)"]
B --> C["Byte (8 bits)"]
C --> D["Word (16/32/64 bits)"]
D --> E["Data Storage"]Why binary?
- Hardware simplicity: Transistors can easily represent two states (on/off).
- Error detection: Single-bit errors are detectable (e.g., parity bits).
- Universal: Used in all low-level operations (CPU, memory, I/O).
Example: Binary in eSewa
When you transfer ₹500 via eSewa, the app converts this decimal number to binary (111110100) for processing. The bank’s server stores this as binary in its database and performs calculations (e.g., deductions, transaction logs) using binary arithmetic.
2. Hexadecimal (Base-16) and Octal (Base-8)
While binary is efficient, it’s verbose for humans. Hexadecimal (hex) and octal simplify representation:
- Hex: Uses digits
0–9and lettersA–F(whereA=10,B=11, ...,F=15). - Octal: Uses digits
0–7.
Conversion Shortcut: Hex and octal are powers of 2, making them easy to convert to/from binary:
- 1 hex digit = 4 binary digits (nibble)
- 1 octal digit = 3 binary digits
flowchart TD
A["Decimal"] -->|"Divide by 16, remainder"| B["Hex"]
A -->|"Divide by 8, remainder"| C["Octal"]
B -->|"Group binary in 4s"| D["Binary"]
C -->|"Group binary in 3s"| DReal-World Example: WhatsApp Encryption
WhatsApp uses hexadecimal to represent encrypted messages. When you send a message, it’s converted to binary, encrypted, and then often displayed in hex format for debugging by developers. For example, the hex 48656C6C6F represents "Hello" in ASCII.
Fixed-Point Number Representation
Fixed-point numbers separate the integer and fractional parts using a fixed binary point (like a decimal point in decimal numbers). This is critical for:
- Financial calculations (e.g., loan interest in banks).
- Sensor data (e.g., temperature readings in IoT devices like smart meters).
How It Works
A fixed-point number is represented as:
S I.F
- S: Sign bit (0 = positive, 1 = negative).
- I: Integer part.
- F: Fractional part.
- The binary point is fixed (e.g., after 8 bits for the integer part).
Example: Storing ₹12.50 in Fixed-Point Assume:
- 8 bits for integer, 8 bits for fraction, 1 bit for sign.
- Binary for 12 =
1100, for 0.5 =10000000(since 0.5 in binary is0.1). - Combined:
0 1100 10000000(sign=0, integer=12, fraction=0.5).
Worked Example: NEPSE Stock Prices NEPSE displays stock prices like ₹1234.56. To store this in fixed-point:
- Convert 1234 to binary:
10011010010. - Convert 0.56 to binary:
0.100011(approximate). - Combine with a fixed binary point (e.g., after 12 bits for integer):
0 10011010010 0011000000(simplified).
Signed Number Representations
Computers must handle negative numbers. Common methods:
Sign-Magnitude: Uses a sign bit (0=+, 1=−) + magnitude.
- Example:
-5=1 0101(sign=1, magnitude=5). - Problem: Two representations for zero (
0000and1000).
- Example:
1’s Complement: Invert all bits of the positive number.
- Example:
5=0101,-5=1010. - Problem: Two zeros (
0000and1111).
- Example:
2’s Complement (Most Used): Add 1 to the 1’s complement.
- Example:
5=0101,-5=1010(1’s complement) +1=1011. - Advantages:
- Single representation for zero.
- Simplifies arithmetic (e.g., subtraction becomes addition).
- Example:
Real-World Example: Bank Loan Calculations When a bank calculates your loan EMI, it uses 2’s complement for negative values (e.g., interest deductions). For example:
- If your principal is
10000(10011100010000) and interest is-500(111111101001111111111111in 2’s complement), the CPU adds these directly in binary.
Conversion Techniques
Decimal ↔ Binary
Method: Divide by 2, record remainders.
Example: Convert 25₁₀ to binary.
25 ÷ 2 = 12 R1
12 ÷ 2 = 6 R0
6 ÷ 2 = 3 R0
3 ÷ 2 = 1 R1
1 ÷ 2 = 0 R1
Read remainders upward: 11001
Result: 25₁₀ = 11001₂.
Binary ↔ Hexadecimal
Method: Group binary into nibbles (4 bits), convert each to hex.
Example: Convert 11010110₂ to hex.
1101 0110 → D 6 → D6
Result: 11010110₂ = D6₁₆.
Binary ↔ Octal
Method: Group binary into triplets (3 bits), convert each to octal.
Example: Convert 101101₂ to octal.
Pad to multiple of 3: 101 101 → 5 5 → 55
Result: 101101₂ = 55₈.
Real-World Applications
1. eSewa and Khalti: Binary for Transactions
- How it works: When you pay via eSewa, the app converts your transaction amount (e.g.,
₹300) to binary (100101100) for processing. - Why binary?: The server’s CPU performs arithmetic (addition/subtraction) in binary for speed.
- Hex in debugging: Developers often view transaction logs in hex (e.g.,
12Cfor300in hex) for compactness.
2. Ncell Billing: Fixed-Point for Charges
- How it works: Ncell calculates your bill (e.g.,
₹456.75) using fixed-point arithmetic. The integer part (456) and fractional part (0.75) are stored separately in memory. - Why fixed-point?: Ensures precision for billing, avoiding rounding errors in decimal-to-binary conversions.
3. Pathao Ride Queues: Binary for Priority
- How it works: Pathao’s algorithm assigns ride requests a priority code in binary. For example:
001= High priority (short distance).010= Medium priority (peak hours).011= Low priority (off-peak).
- Why binary?: Bitwise operations (e.g.,
AND,OR) quickly filter rides based on priority.
4. Daraz Order Processing: Hex for Order IDs
- How it works: Daraz generates order IDs in hexadecimal (e.g.,
A7F2B9). This is easier for humans to read than binary (101001111111001010111001). - Why hex?: Compact (4 hex digits = 16 bits) and reduces errors in manual entry.
Common Pitfalls and Exam Tips
Pitfall 1: Forgetting to Pad Binary for Octal/Hex
- Mistake: Converting
101101₂ to octal as101 101→55₈ (correct), but forgetting to pad to101101→00101101→135₈ if grouped incorrectly. - Fix: Always pad binary to a multiple of 3 (octal) or 4 (hex).
Pitfall 2: Sign Bit Errors in 2’s Complement
- Mistake: Calculating
-5as1010(1’s complement) but forgetting to add1to get1011(2’s complement). - Fix: Remember the rule: 2’s complement = 1’s complement + 1.
Pitfall 3: Confusing Fixed-Point with Floating-Point
- Mistake: Thinking fixed-point can represent very large/small numbers like floating-point.
- Fix: Fixed-point is fixed precision; floating-point (e.g.,
3.14) uses a variable exponent.
Pitfall 4: Unit Mismatches in Conversions
- Mistake: Converting
123.45₁₀ to binary without separating integer/fraction. - Fix: Convert integer and fraction separately, then combine with a binary point.
Exam Tip: Step-by-Step Approach for Conversion Questions
- Identify the base: Is it decimal → binary, hex → binary, or octal → decimal?
- Use the right method:
- Decimal → Binary: Division by 2.
- Binary → Hex/Octal: Grouping and lookup.
- Hex/Octal → Decimal: Expand using powers of 16/8.
- Show all steps: Examiners reward detailed working.
- Verify: Convert back to the original base to check accuracy.
Example Question:
Convert (14.14)_10 to binary and octal.
Solution:
- Integer part (14):
14 ÷ 2 = 7 R07 ÷ 2 = 3 R13 ÷ 2 = 1 R11 ÷ 2 = 0 R1→1110₂.
- Fraction part (0.14):
0.14 × 2 = 0.28→00.28 × 2 = 0.56→10.56 × 2 = 1.12→10.12 × 2 = 0.24→0- (Repeat until desired precision) →
0.001001...₂.
- Combine:
1110.001001₂. - To octal: Group binary into triplets (pad to
1110001001):001 110 001 001→1611₈.
Summary Table: Number Systems Compared
| Feature | Binary (Base-2) | Hexadecimal (Base-16) | Octal (Base-8) |
|---|---|---|---|
| Digits Used | 0, 1 | 0–9, A–F | 0–7 |
| Used By | CPUs, memory | Debugging, shorthand | Legacy systems |
| Conversion | Division by 2 | Group binary in 4s | Group binary in 3s |
| Example | 1010 (10) |
A (10) |
12 (10) |
| Real-World Use | All hardware ops | WhatsApp encryption | Unix file permissions |
Final Checklist for Exams
- Can you convert between decimal, binary, hex, and octal without errors?
- Do you know how fixed-point represents numbers like
123.45in binary? - Can you explain 2’s complement and why it’s preferred over sign-magnitude?
- Can you identify real-world uses (e.g., banking, IoT, apps) for each number system?
- Are you comfortable with bitwise operations (e.g., AND, OR) in binary? (Bonus for exams!)
Based on the TU BSc CSIT syllabus for Introduction to Information Technology (CSC114), unit 3.
Discussion
Loading…