Skip to content

Commit 5bb4459

Browse files
committed
docs(notes): add 2025-03-23-data-representation-en.md
1 parent c3736fc commit 5bb4459

File tree

1 file changed

+254
-0
lines changed

1 file changed

+254
-0
lines changed
+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
---
2+
title: Data Representation and Operation
3+
lang: en
4+
layout: post
5+
audio: false
6+
translated: false
7+
generated: true
8+
---
9+
10+
Below is a comprehensive tutorial that breaks down the key topics in the “Data Representation and Operation” chapter. This tutorial covers binary, hexadecimal, and floating-point number systems, Boolean algebra, and arithmetic operations. It’s designed to build your understanding step by step with clear explanations and examples.
11+
12+
---
13+
14+
## 1. Number Systems
15+
16+
### 1.1 Binary Number System
17+
18+
**Concepts:**
19+
20+
- **Base-2 System:** Uses only two digits: 0 and 1.
21+
- **Place Value:** Each digit represents a power of 2. For a binary number \( b_n b_{n-1} \dots b_1 b_0 \), the value is
22+
\[
23+
\sum_{i=0}^{n} b_i \times 2^i
24+
\]
25+
where \( b_i \) is either 0 or 1.
26+
27+
**Example:**
28+
29+
Convert binary \( 1011_2 \) to decimal:
30+
- \( 1 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 = 8 + 0 + 2 + 1 = 11_{10} \)
31+
32+
**Practice Exercise:**
33+
34+
- Convert the binary number \( 110010_2 \) to decimal.
35+
36+
---
37+
38+
### 1.2 Hexadecimal Number System
39+
40+
**Concepts:**
41+
42+
- **Base-16 System:** Uses sixteen symbols: 0–9 and A–F (where A=10, B=11, …, F=15).
43+
- **Place Value:** Each digit represents a power of 16. For a hexadecimal number \( h_n h_{n-1} \dots h_1 h_0 \), the value is
44+
\[
45+
\sum_{i=0}^{n} h_i \times 16^i
46+
\]
47+
48+
**Conversion from Binary to Hexadecimal:**
49+
50+
1. Group the binary number into 4-bit chunks (starting from the right).
51+
2. Convert each 4-bit group to its hexadecimal equivalent.
52+
53+
**Example:**
54+
55+
Convert binary \( 1011011101_2 \) to hexadecimal:
56+
- Group into 4-bit groups: \( 10 \, 1101 \, 1101 \) (pad left with zeros if needed → \( 0010 \, 1101 \, 1101 \))
57+
- \( 0010_2 = 2_{16} \)
58+
- \( 1101_2 = D_{16} \)
59+
- \( 1101_2 = D_{16} \)
60+
- Final hexadecimal: \( 2DD_{16} \)
61+
62+
**Practice Exercise:**
63+
64+
- Convert the binary number \( 11101010_2 \) into hexadecimal.
65+
66+
---
67+
68+
### 1.3 Floating-Point Number Representation
69+
70+
**Concepts:**
71+
72+
- **Purpose:** To represent real numbers that can have very large or very small magnitudes.
73+
- **IEEE Standard:** Most computers use IEEE 754 for floating-point arithmetic.
74+
- **Components:**
75+
- **Sign Bit:** Determines if the number is positive (0) or negative (1).
76+
- **Exponent:** Represents the scale or magnitude.
77+
- **Mantissa (Significand):** Contains the significant digits of the number.
78+
79+
**Representation:**
80+
81+
For single precision (32-bit):
82+
- 1 bit for sign.
83+
- 8 bits for exponent.
84+
- 23 bits for mantissa.
85+
86+
For example, the value is represented as:
87+
\[
88+
(-1)^{\text{sign}} \times 1.\text{mantissa} \times 2^{(\text{exponent} - \text{bias})}
89+
\]
90+
where the bias for single precision is 127.
91+
92+
**Example Walk-Through:**
93+
94+
Suppose you have a 32-bit binary string representing a floating-point number:
95+
- **Sign Bit:** 0 (positive)
96+
- **Exponent Bits:** e.g., \( 10000010_2 \) → Decimal 130. Subtract bias: \( 130 - 127 = 3 \).
97+
- **Mantissa Bits:** Suppose they represent a fractional part like \( .101000... \).
98+
99+
Then the number would be:
100+
\[
101+
+1.101000 \times 2^3
102+
\]
103+
Convert \( 1.101000 \) from binary to decimal and then multiply by \( 2^3 \) to get the final value.
104+
105+
**Practice Exercise:**
106+
107+
- Given the following breakdown for a 32-bit floating-point number: sign = 0, exponent = \( 10000001_2 \) (decimal 129), and mantissa = \( 01000000000000000000000 \), compute the decimal value.
108+
109+
---
110+
111+
## 2. Boolean Algebra
112+
113+
### 2.1 Basic Boolean Operations
114+
115+
**Key Operations:**
116+
- **AND (·):** \( A \land B \) is true only if both \( A \) and \( B \) are true.
117+
- **OR (+):** \( A \lor B \) is true if at least one of \( A \) or \( B \) is true.
118+
- **NOT (’ or \(\neg\)):** \( \neg A \) inverts the truth value of \( A \).
119+
120+
**Truth Tables:**
121+
122+
- **AND:**
123+
124+
| A | B | A AND B |
125+
|---|---|---------|
126+
| 0 | 0 | 0 |
127+
| 0 | 1 | 0 |
128+
| 1 | 0 | 0 |
129+
| 1 | 1 | 1 |
130+
131+
- **OR:**
132+
133+
| A | B | A OR B |
134+
|---|---|--------|
135+
| 0 | 0 | 0 |
136+
| 0 | 1 | 1 |
137+
| 1 | 0 | 1 |
138+
| 1 | 1 | 1 |
139+
140+
- **NOT:**
141+
142+
| A | NOT A |
143+
|---|-------|
144+
| 0 | 1 |
145+
| 1 | 0 |
146+
147+
**Practice Exercise:**
148+
149+
- Given the Boolean expression \( \neg(A \land B) \), use a truth table to show it is equivalent to \( \neg A \lor \neg B \) (De Morgan’s Law).
150+
151+
---
152+
153+
### 2.2 Boolean Algebra Laws and Theorems
154+
155+
**Important Laws:**
156+
157+
- **Commutative Law:**
158+
- \( A \lor B = B \lor A \)
159+
- \( A \land B = B \land A \)
160+
161+
- **Associative Law:**
162+
- \( (A \lor B) \lor C = A \lor (B \lor C) \)
163+
- \( (A \land B) \land C = A \land (B \land C) \)
164+
165+
- **Distributive Law:**
166+
- \( A \land (B \lor C) = (A \land B) \lor (A \land C) \)
167+
- \( A \lor (B \land C) = (A \lor B) \land (A \lor C) \)
168+
169+
- **De Morgan’s Laws:**
170+
- \( \neg (A \land B) = \neg A \lor \neg B \)
171+
- \( \neg (A \lor B) = \neg A \land \neg B \)
172+
173+
**Practice Exercise:**
174+
175+
- Simplify the expression \( A \lor (\neg A \land B) \) using Boolean algebra laws.
176+
177+
---
178+
179+
## 3. Arithmetic Operations in Different Number Systems
180+
181+
### 3.1 Binary Arithmetic
182+
183+
**Key Operations:**
184+
185+
- **Addition:**
186+
- Follows similar rules to decimal addition but with base 2.
187+
- **Example:** \( 1011_2 + 1101_2 \)
188+
- Align and add bit by bit, carrying over when the sum exceeds 1.
189+
190+
- **Subtraction:**
191+
- Can be performed by borrowing, or by using the two's complement method.
192+
- **Two's Complement:** To represent negative numbers, invert the bits and add 1.
193+
- **Example:** To subtract \( 1101_2 \) from \( 1011_2 \), first find the two's complement of \( 1101_2 \) then add.
194+
195+
**Practice Exercise:**
196+
197+
- Perform the binary subtraction \( 10100_2 - 01101_2 \) using two’s complement.
198+
199+
---
200+
201+
### 3.2 Hexadecimal Arithmetic
202+
203+
**Key Operations:**
204+
205+
- **Addition/Subtraction:** Similar to decimal arithmetic but in base-16.
206+
- **Multiplication/Division:** Also follows the same principles as in decimal; however, you need to convert intermediate results using hexadecimal rules.
207+
208+
**Practice Exercise:**
209+
210+
- Add \( 2A3_{16} \) and \( 1F7_{16} \).
211+
212+
---
213+
214+
### 3.3 Floating-Point Arithmetic
215+
216+
**Challenges:**
217+
218+
- **Rounding Errors:** Due to limited precision, operations may introduce rounding errors.
219+
- **Normalization:** After an operation, the result must be normalized (i.e., the mantissa adjusted so that it fits the required format).
220+
221+
**Example:**
222+
223+
- **Addition:** When adding two floating-point numbers, you must align the exponents before adding the mantissas.
224+
225+
**Practice Exercise:**
226+
227+
- Outline the steps to add two floating-point numbers represented in IEEE 754 format.
228+
229+
---
230+
231+
## 4. Practical Tips for Mastering the Material
232+
233+
- **Work Through Examples:** Practice converting numbers between systems by hand.
234+
- **Build Truth Tables:** For Boolean expressions, construct truth tables to understand and verify equivalences.
235+
- **Use Simulators/Tools:** Many educational websites and software tools allow you to simulate binary arithmetic or IEEE floating-point operations.
236+
- **Practice Problems:** Look for exercises at the end of your textbook chapters or online problem sets related to computer organization.
237+
- **Understand the Theory:** Rather than memorizing steps, focus on understanding why a method (like two’s complement) works.
238+
239+
---
240+
241+
## 5. Summary
242+
243+
This chapter lays the foundation for understanding how computers process and represent data. You’ve learned:
244+
245+
- **Binary and Hexadecimal Systems:** How numbers are represented and converted.
246+
- **Floating-Point Representation:** The structure and function of the IEEE 754 standard.
247+
- **Boolean Algebra:** The logic underpinning digital circuits and how to manipulate Boolean expressions.
248+
- **Arithmetic Operations:** How to perform arithmetic in different number systems, including handling issues like rounding in floating-point arithmetic.
249+
250+
By practicing the examples and exercises provided, you’ll build the competence needed for both academic assessments and practical applications in computer organization and architecture.
251+
252+
---
253+
254+
This tutorial should give you a solid start on the chapter. If you have further questions or need additional examples, feel free to ask!

0 commit comments

Comments
 (0)