Chapter 4
Chapter Overview
The chapter on Data Representation is an essential part of Computer Science, focusing on how data is represented in computers. In this chapter, we will explore the various ways data is represented, including binary, decimal, and hexadecimal numbers. We will also learn about the different types of data representation, such as signed and unsigned numbers, and how they are used in computers. Understanding data representation is crucial for computer programming and is a fundamental concept in computer science.
At its core, a electronic computer is a digital system consisting of billions of microscopic transistors that act as electronic switches. These switches exist in two physical states: ON (high voltage, typically represented as binary digit 1) and OFF (low voltage, represented as binary digit 0). Because modern computer hardware operates strictly on binary states, all external human-understandable information—such as numbers, text, images, video, and audio—must undergo a translation process into binary patterns. This chapter details the positional number systems (Decimal, Binary, Octal, Hexadecimal), conversion algorithms between base systems, integer representation methods (Sign-Magnitude, 1's Complement, 2's Complement), character encoding schemes (ASCII, ISCII, Unicode), and bitwise logic operations that enable computer hardware to perform complex mathematical and logical calculations.
Learning Objectives
- Understand the concept of data representation in computers and why digital hardware relies on binary logic.
- Learn about the different types of data representation, including binary, decimal, octal, and hexadecimal numbers, along with their respective base (radix) properties.
- Understand the concept of signed and unsigned numbers, mastering Sign-Magnitude, 1's Complement, and 2's Complement forms for signed integer arithmetic.
- Learn how to convert between different data representations, including integer and fractional numbers across binary, decimal, octal, and hexadecimal systems.
- Master Character Encoding Standards, such as ASCII, ISCII, and Unicode (UTF-8, UTF-16), to comprehend how textual symbols are digitized.
- Perform Bitwise Logic Operations, applying AND, OR, NOT, XOR, and Bit Shifts to solve low-level data manipulation problems.
- Analyze Real-World Case Studies, such as RGB color hex codes, IP addressing, and hardware overflow errors.
Important Concepts
Binary Numbers
Binary numbers are the base of all computer data representation. They are made up of only two digits: 0 and 1. Binary numbers can be used to represent any type of data, including numbers, characters, and instructions.
The binary system is a base-2 (radix-2) positional number system. Each digit position in a binary number represents an increasing power of 2, starting from 20 on the extreme right (Least Significant Bit or LSB). For example, the binary number (1011.01)2 represents:
(1×23)+(0×22)+(1×21)+(1×20)+(0×2−1)+(1×2−2)=8+0+2+1+0+0.25=(11.25)10
Decimal Numbers
Decimal numbers are the type of numbers we use in everyday life. They are made up of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Decimal numbers can be used to represent large numbers, but they are not as efficient as binary numbers for computer use.
The decimal system is a base-10 (radix-10) positional system where each digit's value depends on its position relative to the decimal point, multiplied by powers of 10. While humans find base-10 intuitive due to ten fingers, implementing ten distinct physical voltage states in computer hardware would lead to extreme noise sensitivity and circuit unreliability. Hence, digital computers convert base-10 input into binary for internal processing and back to decimal for human display.
Octal Numbers
The octal number system is a base-8 (radix-8) positional number system that uses eight distinct digits: 0, 1, 2, 3, 4, 5, 6, and 7.
Octal serves as a compact shorthand notation for binary numbers because 8=23. This means every single octal digit precisely represents a group of 3 binary bits. For instance, the binary pattern 111 corresponds directly to octal 7. Octal was widely used in legacy computing architectures (such as PDP-8 and UNIX file permissions like chmod 755).
Hexadecimal Numbers
Hexadecimal numbers are a type of number that uses 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Hexadecimal numbers are often used in computer programming to represent colors, addresses, and other types of data.
The hexadecimal system is a base-16 (radix-16) system. The alphabetic characters A through F correspond to decimal values 10 through 15:
- A=10, B=11, C=12, D=13, E=14, F=15.
Because 16=24, 1 hexadecimal digit represents exactly 4 binary bits (1 nibble). This allows long, human-unfriendly binary strings to be expressed compactly. For example, the 16-bit binary value 1101001110100101 can be written as D3A5 in hexadecimal.
Signed and Unsigned Numbers
Signed numbers can be either positive or negative, while unsigned numbers are always positive. Signed numbers are used to represent temperatures, heights, and other types of data that can be negative.
Unsigned Representation
In an n-bit unsigned representation, all n bits are reserved exclusively for magnitude. The range of expressible values for an n-bit unsigned integer is:
Rangeunsigned=[0 to 2n−1]
For an 8-bit unsigned integer, the range is 0 to 28−1, i.e., 0 to 255.
Signed Representation Techniques
When negative numbers must be represented, the most significant bit (MSB) is designated as the Sign Bit (0 for Positive, 1 for Negative). There are three standard schemes for signed integers:
-
Sign-Magnitude Representation:
- Leftmost bit (MSB) = Sign bit (0=+,1=−).
- Remaining (n−1) bits = Binary magnitude of the number.
- Drawback: Dual representation of zero (+0 as
00000000 and −0 as 10000000), which complicates arithmetic hardware circuits.
-
1's Complement Representation:
- Positive numbers are represented in standard binary logic.
- Negative numbers are formed by inverting all bits (changing 0→1 and 1→0) of their positive counterpart.
- Drawback: Still contains dual representations of zero (
00000000 for +0 and 11111111 for −0).
-
2's Complement Representation (Standard in Modern Hardware):
- Positive numbers are represented in standard binary logic.
- Negative numbers are formed by taking the 1's complement of the number and adding 1 to the Least Significant Bit (LSB):
2’s Complement=1’s Complement+1
- Advantages: Only one unique zero (
00000000), and hardware subtraction can be performed directly using simple addition circuits without needing special subtraction logic.
- Range for n-bit 2's Complement system:
Range2’s Complement=[−2n−1 to 2n−1−1]
For 8 bits, this range is −128 to +127.
Character Encoding Systems
To process textual data, computers map characters (letters, symbols, digits) to unique numerical values using standard character encoding schemes:
-
ASCII (American Standard Code for Information Interchange):
- Originally a 7-bit code, representing 27=128 characters (values 0 to 127). It covers English alphabets (A-Z, a-z), digits (0-9), punctuation marks, and control characters (e.g., newline, backspace).
- Extended ASCII uses 8 bits (1 byte) to represent 28=256 characters, adding special symbols and accented European letters.
- Key ASCII Code Ranges:
'A' to 'Z': 65 to 90
'a' to 'z': 97 to 122 (Note: Difference between lowercase and uppercase is 32, i.e., bit 5 toggled)
'0' to '9': 48 to 57
-
ISCII (Indian Standard Code for Information Interchange):
- An 8-bit character code developed in India to represent various Indian scripts (Devanagari, Bengali, Gurmukhi, Gujarati, Tamil, Telugu, etc.) alongside ASCII characters. Retains standard ASCII in the upper 0–127 range and places Indian script symbols in the 128–255 range.
-
Unicode:
- Developed to provide a single, universal character encoding standard capable of representing all writing systems across the world (including Latin, Cyrillic, Chinese, Japanese, Arabic, Emojis, and mathematical symbols).
- Unicode Encodings:
- UTF-8: Variable-length encoding (1 to 4 bytes). Fully backward-compatible with 7-bit ASCII. Highly efficient for web usage.
- UTF-16: Variable-length encoding (2 or 4 bytes). Used internally by Windows, Java, and JavaScript environments.
- UTF-32: Fixed-length 4-byte (32-bit) encoding, mapping up to 1,114,112 code points directly.
Bitwise Operations
Bitwise operations are used to manipulate binary numbers. They include operations such as AND, OR, and NOT.
Bitwise operators manipulate data directly at the individual bit level. These operations are extremely fast as they execute natively within the CPU's Arithmetic Logic Unit (ALU).
1. Bitwise AND (&)
Returns 1 if and only if both corresponding input bits are 1; otherwise, returns 0.
\hline
\mathbf{A} & \mathbf{B} & \mathbf{A \ \& \ B} \\
\hline
0 & 0 & 0 \\
0 & 1 & 0 \\
1 & 0 & 0 \\
1 & 1 & 1 \\
\hline
\end{array}$$
#### 2. Bitwise OR (`|`)
Returns `1` if **at least one** of the corresponding input bits is `1`; returns `0` only when both bits are `0`.
$$\begin{array}{|c|c|c|}
\hline
\mathbf{A} & \mathbf{B} & \mathbf{A \ | \ B} \\
\hline
0 & 0 & 0 \\
0 & 1 & 1 \\
1 & 0 & 1 \\
1 & 1 & 1 \\
\hline
\end{array}$$
#### 3. Bitwise XOR (`^`) - Exclusive OR
Returns `1` if the corresponding input bits are **different**; returns `0` if they are identical.
$$\begin{array}{|c|c|c|}
\hline
\mathbf{A} & \mathbf{B} & \mathbf{A \ \oplus \ B} \\
\hline
0 & 0 & 0 \\
0 & 1 & 1 \\
1 & 0 & 1 \\
1 & 1 & 0 \\
\hline
\end{array}$$
#### 4. Bitwise NOT (`~`) - Complement
A unary operator that inverts every bit of the operand ($0 \to 1$ and $1 \to 0$).
#### 5. Bitwise Shift Operators
- **Left Shift (`<<`)**: Shifts bits to the left by $k$ positions, filling vacated LSB positions with `0`. Multiplying an unsigned integer by $2^k$ is equivalent to left-shifting by $k$.
- **Right Shift (`>>`)**: Shifts bits to the right by $k$ positions. Dividing an unsigned integer by $2^k$ (integer division) is equivalent to right-shifting by $k$.
---
## Key Definitions
- **Binary Number**: A number made up of only two digits: 0 and 1, operating on base-2 positional logic.
- **Decimal Number**: A number made up of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, operating on base-10 positional logic.
- **Hexadecimal Number**: A number made up of 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, operating on base-16 positional logic.
- **Octal Number**: A positional number system using base-8 with digits 0 through 7.
- **Signed Number**: A number that can be either positive or negative, utilizing mechanisms like 2's Complement or Sign-Magnitude to represent polarity.
- **Unsigned Number**: A number that is always positive or zero, utilizing all available bits solely to store numerical magnitude.
- **Radix (Base)**: The total count of unique single-digit symbols available in a given positional number system.
- **Least Significant Bit (LSB)**: The rightmost bit in a binary string, carrying the lowest power weight ($2^0$).
- **Most Significant Bit (MSB)**: The leftmost bit in a binary string, carrying the highest positional weight, or indicating sign polarity in signed binary systems.
- **ASCII**: A standard 7-bit/8-bit encoding system that assigns numerical codes to English textual characters and control symbols.
- **Unicode**: A universal multi-byte character encoding standard designed to uniquely encode symbols across all written languages in existence.
---
## Important Terms
| Term | Meaning | Equivalent / Weight |
| :--- | :--- | :--- |
| **Bit** | A single binary digit (0 or 1) | Smallest unit of data ($2^0$) |
| **Nibble** | A group of 4 binary digits (0s and 1s) | $1\text{ Nibble} = 4\text{ bits} = 1\text{ Hex digit}$ |
| **Byte** | A group of 8 binary digits (0s and 1s) | $1\text{ Byte} = 8\text{ bits} = 2\text{ Nibbles}$ |
| **Kilobyte (KB)** | Measurement unit for memory/data size | $1\text{ KB} = 1024\text{ Bytes} = 2^{10}\text{ Bytes}$ |
| **Megabyte (MB)** | Measurement unit for memory/data size | $1\text{ MB} = 1024\text{ KB} = 2^{20}\text{ Bytes}$ |
| **Gigabyte (GB)** | Measurement unit for memory/data size | $1\text{ GB} = 1024\text{ MB} = 2^{30}\text{ Bytes}$ |
| **Terabyte (TB)** | Measurement unit for memory/data size | $1\text{ TB} = 1024\text{ GB} = 2^{40}\text{ Bytes}$ |
| **Petabyte (PB)** | Measurement unit for memory/data size | $1\text{ PB} = 1024\text{ TB} = 2^{50}\text{ Bytes}$ |
| **Word Length** | Number of bits processed by a CPU in a single cycle | E.g., 32-bit architecture, 64-bit architecture |
---
## Important Formulas
### 1. General Base-to-Decimal Expansion Formula
For a number with $n$ integer digits and $m$ fractional digits in base $b$:
$$N_{10} = \sum_{i=-m}^{n-1} d_i \times b^i = (d_{n-1} \cdot b^{n-1}) + \dots + (d_0 \cdot b^0) + (d_{-1} \cdot b^{-1}) + \dots + (d_{-m} \cdot b^{-m})$$
### 2. Maximum Unsigned Integer Value Formula
For $n$ bits in an unsigned system:
$$\text{Maximum Value} = 2^n - 1$$
$$\text{Total Unique States} = 2^n$$
### 3. Signed Integer Ranges ($n$ bits)
- **Sign-Magnitude Range**: $[-(2^{n-1} - 1) \text{ to } +(2^{n-1} - 1)]$
- **1's Complement Range**: $[-(2^{n-1} - 1) \text{ to } +(2^{n-1} - 1)]$
- **2's Complement Range**: $[-2^{n-1} \text{ to } +(2^{n-1} - 1)]$
### 4. 2's Complement Math Formula
$$\text{2's Complement of } X = (2^n - X)_{10} = (\text{1's Complement of } X) + 1$$
---
## Diagrams (Description Only)
### Diagram 1: Positional Bit Weighting Layout
- **Description**: A horizontal array of 8 register boxes representing an 8-bit binary pattern `11010110.101`.
- **Labels**:
- The bit positions left of the decimal point are indexed $7, 6, 5, 4, 3, 2, 1, 0$, with corresponding positional weights $2^7 (128), 2^6 (64), 2^5 (32), 2^4 (16), 2^3 (8), 2^2 (4), 2^1 (2), 2^0 (1)$.
- The leftmost bit (position 7) is pointed to with an arrow labeled **"MSB (Most Significant Bit)"**.
- The bit immediately to the left of the point (position 0) is pointed to with an arrow labeled **"LSB (Least Significant Bit for integers)"**.
- The bit positions right of the point are indexed $-1, -2, -3$ with fractional weights $2^{-1} (0.5), 2^{-2} (0.25), 2^{-3} (0.125)$.
### Diagram 2: 8-Bit Signed Register Comparison
- **Description**: Three parallel 8-bit registers illustrating how the negative number $-13_{10}$ is represented across three conventions:
- **Sign-Magnitude Register**: Bit 7 contains `1` (Sign bit set to negative), and bits 6 down to 0 contain `0001101` (binary magnitude of 13). Full pattern: `10001101`.
- **1's Complement Register**: Bitwise inversion of $+13$ (`00001101`). Full pattern: `11110010`.
- **2's Complement Register**: 1's Complement pattern `11110010` plus `1`. Full pattern: `11110011`.
### Diagram 3: Binary-to-Hexadecimal 4-Bit Grouping Map
- **Description**: A 16-bit binary string `1100101011110001` split by vertical dashed lines into four 4-bit nibbles: `[1100] [1010] [1111] [0001]`.
- **Mapping arrows**:
- `1100` $\to$ Decimal $12$ $\to$ Hex `C`
- `1010` $\to$ Decimal $10$ $\to$ Hex `A`
- `1111` $\to$ Decimal $15$ $\to$ Hex `F`
- `0001` $\to$ Decimal $1$ $\to$ Hex `1`
- **Output**: Hexadecimal result `= CAF1_{16}`.
---
## Step-by-Step Problem-Solving Strategies & Conversions
### Type 1: Conversion from Base-$b$ to Decimal (Base 10)
**Method**: Multiply each digit by its positional weight ($b^i$) and sum the results.
#### Example 1.1: Convert $(110101.11)_2$ to Decimal
1. Write down integer positional powers: $2^5, 2^4, 2^3, 2^2, 2^1, 2^0$
2. Write down fractional positional powers: $2^{-1}, 2^{-2}$
3. Expand:
$$(1 \times 32) + (1 \times 16) + (0 \times 8) + (1 \times 4) + (0 \times 2) + (1 \times 1) + (1 \times 0.5) + (1 \times 0.25)$$
$$= 32 + 16 + 0 + 4 + 0 + 1 + 0.5 + 0.25 = \mathbf{53.75_{10}}$$
#### Example 1.2: Convert $(3A7.C)_{16}$ to Decimal
1. Map hex digits to decimal: $3 \to 3$, $A \to 10$, $7 \to 7$, $C \to 12$.
2. Expand positional powers of 16:
$$(3 \times 16^2) + (10 \times 16^1) + (7 \times 16^0) + (12 \times 16^{-1})$$
$$= (3 \times 256) + (10 \times 16) + (7 \times 1) + \left(\frac{12}{16}\right)$$
$$= 768 + 160 + 7 + 0.75 = \mathbf{935.75_{10}}$$
---
### Type 2: Conversion from Decimal (Base 10) to Target Base-$b$
**Method**:
- For the **integer part**: Repeatedly divide by base $b$ and record the remainders bottom-up (MSB to LSB).
- For the **fractional part**: Repeatedly multiply by base $b$ and record the integer parts top-down.
#### Example 2.1: Convert $(105.625)_{10}$ to Binary
**Step A: Integer Part (105)**
- $105 \div 2 = 52$, Remainder = **1** (LSB)
- $52 \div 2 = 26$, Remainder = **0**
- $26 \div 2 = 13$, Remainder = **0**
- $13 \div 2 = 6$, Remainder = **1**
- $6 \div 2 = 3$, Remainder = **0**
- $3 \div 2 = 1$, Remainder = **1**
- $1 \div 2 = 0$, Remainder = **1** (MSB)
Reading remainders from bottom to top: $(105)_{10} = (1101001)_2$
**Step B: Fractional Part (0.625)**
- $0.625 \times 2 = \mathbf{1}.25$ (Integer part = 1)
- $0.25 \times 2 = \mathbf{0}.50$ (Integer part = 0)
- $0.50 \times 2 = \mathbf{1}.00$ (Integer part = 1, fractional part is 0 $\to$ Stop)
Reading integer parts from top to bottom: $(0.625)_{10} = (.101)_2$
**Final Result**: $(105.625)_{10} = \mathbf{(1101001.101)_2}$
---
### Type 3: Direct Conversions between Binary, Octal, and Hexadecimal
#### Rule for Binary $\leftrightarrow$ Octal
Group binary bits into **3-bit groups** starting from the binary point (pad with leading/trailing zeros if necessary).
- Example: Convert $(10111011)_2$ to Octal.
- Grouping: `010` `111` `011`
- Mapping: $010_2 = 2_8$, $111_2 = 7_8$, $011_2 = 3_8$
- Result: $\mathbf{(273)_8}$
#### Rule for Binary $\leftrightarrow$ Hexadecimal
Group binary bits into **4-bit groups** starting from the binary point.
- Example: Convert $(10111011)_2$ to Hexadecimal.
- Grouping: `1011` `1011`
- Mapping: $1011_2 = 11_{10} = B_{16}$
- Result: $\mathbf{(BB)_{16}}$
---
### Type 4: Subtraction using 2's Complement Arithmetic
To perform $(A - B)$ in an $n$-bit register:
1. Find the $n$-bit binary representation of $A$.
2. Find the $n$-bit 2's complement representation of $B$.
3. Add $A$ and the 2's complement of $B$.
4. **Discard any end-around carry bit** beyond $n$ bits.
#### Example 4.1: Subtract $14_{10}$ from $25_{10}$ using 8-bit 2's Complement
- $A = +25_{10} = 00011001_2$
- $B = +14_{10} = 00001110_2$
**Step 1**: Find 2's complement of $B$ ($-14_{10}$):
- Binary of $+14$: `00001110`
- 1's Complement: `11110001`
- Add 1: `11110001 + 1 = 11110010` (This is $-14_{10}$)
**Step 2**: Add $A$ and 2's complement of $B$:
$$\begin{array}{r@{\quad}l}
00011001 & (+25) \\
+ 11110010 & (-14) \\
\hline
(1)00001011 &
\end{array}$$
**Step 3**: Discard the carry bit `(1)` in $2^8$ place.
- Remaining 8-bit result: `00001011`
- Verification: $00001011_2 = 8 + 2 + 1 = \mathbf{+11_{10}}$. Correct!
---
## Real-Life Applications
Data representation is used in many real-life applications, including:
- **Computer programming**: Low-level bitwise manipulation optimizes memory usage, structures data fields, and controls hardware registers directly.
- **Data storage and retrieval**: Storage media like SSDs and Hard Drives organize data in sectors and blocks expressed in bytes, kilobytes, and terabytes.
- **Networking and communication**: IP addresses (IPv4 written in dotted-decimal like `192.168.1.1` converted from 32-bit binary; IPv6 written in 128-bit Hexadecimal groups) depend directly on data representation standards.
- **Graphics and multimedia**:
- Digital colors are represented using 24-bit **RGB Hex Code Triplets** (e.g., `#FF5733` where `FF` = Red magnitude 255, `57` = Green magnitude 87, `33` = Blue magnitude 51).
- Audio files sample continuous analog waveforms into discrete 16-bit or 24-bit binary values.
---
## Deep-Dive Case Studies
### Case Study 1: The Ariane 5 Flight 501 Disaster (Integer Overflow)
On June 4, 1996, the unmanned Ariane 5 rocket exploded 37 seconds after launch, resulting in a loss of over $370 million.
- **The Technical Root Cause**: An integer overflow error occurred within the inertial reference system software.
- **Data Representation Context**: The software attempted to convert a 64-bit floating-point variable measuring the rocket's horizontal velocity into a **16-bit signed integer**.
- **Why it Failed**: The horizontal velocity value exceeded $32,767$ (the maximum positive value expressible in a 16-bit signed 2's complement register, range $-32,768$ to $+32,767$). The conversion triggered an unhandled hardware exception, causing the flight computer to crash and sending bad diagnostic data to the engines, causing self-destruction.
- **Lesson**: Proper understanding of register sizes, bit-widths, and numeric ranges is critical for mission-critical software safety.
### Case Study 2: UTF-8 Encoding Domination on the World Wide Web
In the early days of computing, different countries used disparate 8-bit ASCII extensions (like Windows-1252 for English/Western Europe, KOI8-R for Russian, Shift-JIS for Japanese). Opening a document authored in one system on a computer using another resulted in garbled text known as *Mojibake*.
- **The Solution**: Unicode standard was introduced, and **UTF-8** became its dominant web implementation.
- **How UTF-8 Works**:
- Uses 1 byte for ASCII characters (Code points `00` to `7F`), maintaining complete backward compatibility with traditional ASCII systems.
- Uses 2, 3, or 4 bytes for non-English scripts, complex symbols, and modern emojis.
- **Impact**: Today, over 98% of all websites globally use UTF-8 encoding, allowing multilingual text rendering in web browsers without code page conflicts.
---
## Key Points to Remember
- Binary numbers are the base of all computer data representation.
- Decimal numbers are used in everyday life, but are not as efficient as binary numbers for computer use.
- Hexadecimal numbers are used to represent colors, addresses, and other types of data.
- Signed numbers can be either positive or negative, while unsigned numbers are always positive.
- Bitwise operations are used to manipulate binary numbers.
- In 2's complement system, negative numbers are calculated by taking 1's complement and adding 1.
- Modern digital CPUs perform subtraction internally by performing 2's complement addition.
- UTF-8 is a variable-width Unicode encoding backward-compatible with 7-bit ASCII.
- An $n$-bit 2's complement system represents values from $-2^{n-1}$ to $2^{n-1}-1$.
- Hexadecimal provides a compact representation where 1 hex digit corresponds to exactly 4 binary bits (1 nibble).
---
## Common Mistakes
- **Confusing binary numbers with decimal numbers**: Assuming `1010` is "One Thousand Ten" instead of binary ten ($10_{10}$). Always write base subscripts when ambiguity exists: $(1010)_2 \neq (1010)_{10}$.
- **Not understanding the difference between signed and unsigned numbers**: Assuming an 8-bit string `10000001` always equals decimal $129$. In unsigned systems, it equals $129$; in 8-bit 2's complement signed systems, it represents $-127$.
- **Not knowing how to convert between different data representations**: Forgetting to process the fractional part of a number by repeated multiplication, mistakenly applying integer division rules to fractions.
- **Forgetting to Pad Binary Groups**: When converting binary to hexadecimal or octal, grouping bits from left to right instead of starting from the binary point, leading to incorrect power alignments.
- **Ignoring Carry-Out in 2's Complement Addition**: Failing to discard the extra overflow bit outside the fixed register length during signed arithmetic operations.
---
## Quick Revision
1. Binary numbers are made up of 0s and 1s.
2. Decimal numbers are made up of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
3. Hexadecimal numbers are made up of 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
4. Signed numbers can be either positive or negative.
5. Unsigned numbers are always positive.
6. Bitwise operations are used to manipulate binary numbers.
7. Binary numbers can be used to represent any type of data.
8. Decimal numbers are not as efficient as binary numbers for computer use.
9. Hexadecimal numbers are used to represent colors, addresses, and other types of data.
10. Data representation is used in many real-life applications.
11. Octal numbers use base-8 with digits 0 through 7.
12. $1 \text{ Byte} = 8 \text{ bits}$, $1 \text{ Nibble} = 4 \text{ bits}$.
13. 2's complement is derived as: $\text{1's Complement} + 1$.
14. An 8-bit 2's complement register has a range of $-128 \text{ to } +127$.
15. ASCII uses 7 bits natively to represent 128 standard characters.
16. Unicode UTF-8 uses variable lengths from 1 to 4 bytes per symbol.
17. Left shift (`<<`) multiplies an unsigned integer by powers of 2.
18. Right shift (`>>`) divides an unsigned integer by powers of 2.
19. Bitwise XOR (`^`) outputs `1` when inputs are different, and `0` when identical.
20. In 2's complement subtraction, the end-around carry outside the register length is discarded.
---
## Chapter Summary
In this chapter, we learned about data representation in computers. We explored the different types of data representation, including binary, decimal, octal, and hexadecimal numbers. We also learned about the concept of signed and unsigned numbers, and how they are used in computers. Understanding data representation is crucial for computer programming and is a fundamental concept in computer science. We also discussed the importance of data representation in real-life applications, including computer programming, data storage and retrieval, networking and communication, and graphics and multimedia. Furthermore, we analyzed step-by-step mathematical procedures for base conversions, complement arithmetic for binary subtraction, character encodings (ASCII, ISCII, Unicode), and low-level bitwise operations.
---
## Higher-Order Thinking Skills (HOTS) Questions
### Question 1
**An 8-bit memory register contains the bit pattern `11111000`. Determine the decimal value represented by this bit pattern under the following interpretations:**
1. Unsigned integer
2. Signed magnitude representation
3. 2's complement representation
#### Solution:
1. **Unsigned Integer**:
All 8 bits contribute to magnitude:
$$1 \times 2^7 + 1 \times 2^6 + 1 \times 2^5 + 1 \times 2^4 + 1 \times 2^3 + 0 + 0 + 0$$
$$= 128 + 64 + 32 + 16 + 8 = \mathbf{248_{10}}$$
2. **Signed Magnitude Representation**:
- MSB bit 7 is `1`, indicating a **negative** value.
- Remaining 7 bits `1111000` represent magnitude:
$$1 \times 2^6 + 1 \times 2^5 + 1 \times 2^4 + 1 \times 2^3 = 64 + 32 + 16 + 8 = 120_{10}$$
- Value = $\mathbf{-120_{10}}$
3. **2's Complement Representation**:
- MSB bit 7 is `1`, indicating a negative value.
- Take 2's complement of `11111000` to find positive magnitude:
- Invert bits (1's complement): `00000111`
- Add 1: `00000111 + 1 = 00001000` ($8_{10}$)
- Value = $\mathbf{-8_{10}}$
---
### Question 2
**Perform binary addition $(-18)_{10} + (+27)_{10}$ using an 8-bit 2's complement representation and show that it yields the correct decimal answer.**
#### Solution:
1. **Represent $+27_{10}$ in 8-bit binary**:
$$27 = 16 + 8 + 2 + 1 = (00011011)_2$$
2. **Represent $-18_{10}$ in 8-bit 2's complement**:
- Binary of $+18$: `00010010`
- 1's Complement: `11101101`
- Add 1: `11101101 + 1 = 11101110` ($-18_{10}$)
3. **Add the two 8-bit patterns**:
$$\begin{array}{r@{\quad}l}
11101110 & (-18) \\
+ 00011011 & (+27) \\
\hline
(1)00001001 &
\end{array}$$
4. **Process Carry**:
- Discard MSB overflow carry `(1)`.
- Remaining 8 bits: `00001001`
- MSB is `0` (positive).
- Magnitude: $2^3 + 2^0 = 8 + 1 = \mathbf{+9_{10}}$.
- Verification: $-18 + 27 = +9$. Correct!
---
## Previous Year Questions (PYQs) with Solutions
### PYQ 1 (1 Mark)
**What is the hex equivalent of binary $(1010111101)_2$?**
- **Solution**:
Group into 4-bit nibbles from right to left:
`0010` `1011` `1101`
- $0010_2 = 2_{16}$
- $1011_2 = B_{16}$
- $1101_2 = D_{16}$
- **Answer**: $(2BD)_{16}$
### PYQ 2 (2 Marks)
**Convert $(75.375)_{10}$ into its Octal equivalent.**
- **Solution**:
- Integer part $75 \div 8$:
- $75 \div 8 = 9$, Remainder = **3**
- $9 \div 8 = 1$, Remainder = **1**
- $1 \div 8 = 0$, Remainder = **1**
- Integer octal = $(113)_8$
- Fractional part $0.375 \times 8$:
- $0.375 \times 8 = \mathbf{3}.00 \to$ Integer part = **3**
- **Answer**: $(113.3)_8$
### PYQ 3 (2 Marks)
**Explain the main difference between ASCII and Unicode.**
- **Solution**:
- **ASCII** is an 7-bit (or extended 8-bit) character encoding scheme that can represent up to $128$ (or $256$) unique characters, restricted primarily to the English alphabet, numbers, and basic symbols.
- **Unicode** is a universal multi-byte encoding system (supporting UTF-8, UTF-16, UTF-32) that can represent over 1.1 million code points, capable of encoding characters across virtually all global written languages, technical scripts, and symbols.
---
## NCERT Textbook Questions & Detailed Answers
### Question 1: Do as directed:
**(a) Convert binary $(1101001)_2$ to decimal.**
- **Solution**:
$$(1 \times 2^6) + (1 \times 2^5) + (0 \times 2^4) + (1 \times 2^3) + (0 \times 2^2) + (0 \times 2^1) + (1 \times 2^0)$$
$$= 64 + 32 + 0 + 8 + 0 + 0 + 1 = \mathbf{105_{10}}$$
**(b) Convert decimal $(122)_{10}$ to binary.**
- **Solution**:
- $122 \div 2 = 61$, Remainder = 0
- $61 \div 2 = 30$, Remainder = 1
- $30 \div 2 = 15$, Remainder = 0
- $15 \div 2 = 7$, Remainder = 1
- $7 \div 2 = 3$, Remainder = 1
- $3 \div 2 = 1$, Remainder = 1
- $1 \div 2 = 0$, Remainder = 1
- Reading bottom-up: $\mathbf{(1111010)_2}$
**(c) Convert octal $(76)_8$ to binary.**
- **Solution**:
Replace each octal digit with its 3-bit binary equivalent:
- $7_8 = 111_2$
- $6_8 = 110_2$
- Result: $\mathbf{(111110)_2}$
**(d) Convert hexadecimal $(4F)_16$ to decimal.**
- **Solution**:
$$(4 \times 16^1) + (15 \times 16^0) = 64 + 15 = \mathbf{79_{10}}$$
---
### Question 2: What is the significance of base/radix in a number system? Give examples of four number systems with their base values.
- **Solution**:
The **base** or **radix** of a number system denotes the total number of unique digits or symbols available in that system to represent numbers. The positional value of each digit is a power of the base.
**Four Number Systems**:
1. **Binary Number System**: Base = 2 (Digits: 0, 1)
2. **Octal Number System**: Base = 8 (Digits: 0, 1, 2, 3, 4, 5, 6, 7)
3. **Decimal Number System**: Base = 10 (Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
4. **Hexadecimal Number System**: Base = 16 (Digits: 0–9 and A–F)
---
### Question 3: Encode the word "DATA" into ASCII decimal values.
- **Solution**:
Referencing standard ASCII character tables:
- `'D'` = $68$
- `'A'` = $65$
- `'T'` = $84$
- `'A'` = $65$
**ASCII Decimal Code Sequence**: **`68 65 84 65`**
---
### Question 4: Differentiate between 1's complement and 2's complement of a binary number with a suitable example.
- **Solution**:
| Characteristic | 1's Complement | 2's Complement |
| :--- | :--- | :--- |
| **Definition** | Obtained by inverting all bits ($0 \to 1, 1 \to 0$). | Obtained by adding $1$ to the 1's complement. |
| **Zero Representation** | Dual zero ($+0$ and $-0$ exist). | Single unique zero representation. |
| **Arithmetic Logic** | Requires end-around carry addition. | Direct binary addition without carry adjustments. |
**Example using 8-bit binary for $+5$ (`00000101`):**
- **1's Complement of $+5$**: `11111010` (represents $-5$ in 1's complement)
- **2's Complement of $+5$**: `11111010 + 1 = 11111011` (represents $-5$ in 2's complement)