Chapitre 5
Representing data in Computer Systems
Lecture : 17 minQuiz de 12 questions
# Representing data in Computer Systems
## Objectifs et prérequis
This chapter aims to equip Lower Sixth students with a comprehensive understanding of how data is represented within computer systems. Students will learn to identify hardware components, perform base conversions, manipulate number systems, represent signed integers, and encode characters, images, and sound. By the end, they will be able to solve problems involving data representation and arithmetic in binary, octal, and hexadecimal systems, and apply this knowledge to real-world computing scenarios.
Prerequisites: Basic arithmetic operations, familiarity with decimal number system, understanding of what a computer is and its general purpose, ability to follow logical sequences.
## Introduction
Data representation is fundamental to computer science. All information processed by a computer—whether numbers, text, images, or sound—must be converted into a format the machine can understand: binary digits (bits). This chapter explores how computer hardware enables this process, how different number systems are used and converted, how signed numbers are handled, and how multimedia data is encoded. Understanding these concepts is essential for grasping how software interacts with hardware and how data integrity is maintained in digital systems.
## I. Computer Hardware Components and Embedded Systems – Part 1
### Definition and Role of Hardware
Computer hardware refers to the physical components of a computer system that can be touched and manipulated. These components work together to input, process, store, and output data.
> **Key Hardware Components**: The central processing unit (CPU), memory (RAM and ROM), storage devices (HDD, SSD), input devices (keyboard, mouse), and output devices (monitor, printer) form the core of a von Neumann architecture system.
The CPU executes instructions fetched from memory. The arithmetic logic unit (ALU) within the CPU performs mathematical and logical operations. The control unit (CU) directs the operation of the processor. Memory stores data and instructions temporarily (RAM) or permanently (ROM). Storage devices retain data long-term.
### Example: Data Flow in a Simple Operation
When a user types 'A' on the keyboard:
1. The keyboard sends an electrical signal corresponding to the key press.
2. The input controller translates this into a binary code (e.g., 01000001 for 'A' in ASCII).
3. This code is sent via the system bus to the CPU.
4. The CPU stores it in RAM temporarily.
5. If instructed to display, the CPU sends the code to the graphics card.
6. The graphics card converts it to a visual signal for the monitor.
### Exercise 1: Identify Hardware Components
List three hardware components involved when saving a document to a USB drive and state their function.
**Solution**:
1. Keyboard (input): Used to type the document.
2. CPU (processing): Executes the save command from the application.
3. USB port and flash memory (storage/output): Receives and stores the document data.
### Exercise 2: True or False
The ROM stores user data that can be modified during normal operation.
**Solution**: False. ROM (Read-Only Memory) stores firmware or boot instructions and is not typically modified during normal operation; it is non-volatile but not user-writable in standard use.
## II. Computer Hardware Components and Embedded Systems – Part 2
### Embedded Systems
An embedded system is a specialized computer system designed to perform one or a few dedicated functions, often with real-time computing constraints. It is embedded as part of a larger device.
> **Characteristics of Embedded Systems**: Dedicated function, real-time response, resource-constrained (limited memory, processing power), often lacks a traditional OS, and is tightly integrated with hardware.
Examples include microcontrollers in washing machines, engine control units in cars, and firmware in digital watches.
### Hardware in Embedded Systems
Embedded systems typically consist of:
- A microcontroller or microprocessor (CPU core)
- Memory (RAM, ROM, sometimes flash)
- Input/output interfaces (sensors, actuators)
- Power supply
- Sometimes communication modules (e.g., Bluetooth, Wi-Fi)
Unlike general-purpose computers, embedded systems often run a single application stored in ROM and are optimized for cost, power, and size.
### Example: Digital Thermostat
A digital thermostat uses:
- A temperature sensor (input) to read room temperature.
- A microcontroller to compare the reading to a set point.
- A relay (output) to turn the heating system on or off.
- Memory to store the set point and firmware.
- The entire system is embedded in the wall unit.
### Exercise 3: Embedded vs General-Purpose
Is a smartphone an embedded system or a general-purpose computer? Justify.
**Solution**: A smartphone is a general-purpose computer. Although it contains embedded components (e.g., modem, sensor controllers), it runs a full operating system (Android/iOS), supports multiple applications, and allows user-installed software—characteristics of a general-purpose system.
### Exercise 4: Function Identification
In an embedded system controlling a microwave oven, what is the role of the keypad?
**Solution**: The keypad is an input device that allows the user to set cooking time and power level; it sends signals to the microcontroller for processing.
## III. Base Conversions
### Number Systems Overview
Computers use binary (base-2) because transistors have two stable states (on/off). However, octal (base-8) and hexadecimal (base-16) are used as shorthand for binary due to their ease of conversion.
> **Conversion Principle**: To convert from base *b* to decimal, multiply each digit by *b* raised to the power of its position (starting from 0 on the right) and sum the results.
### Decimal to Binary
Repeated division by 2, recording remainders from bottom to top.
#### 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
Reading remainders from bottom to top: 1101₂
**Verification**: 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13₁₀ ✓
### Decimal to Octal
Repeated division by 8.
#### Example: Convert 83₁₀ to octal
83 ÷ 8 = 10 remainder 3
10 ÷ 8 = 1 remainder 2
1 ÷ 8 = 0 remainder 1
Reading remainders bottom to top: 123₈
**Verification**: 1×8² + 2×8¹ + 3×8⁰ = 64 + 16 + 3 = 83₁₀ ✓
### Decimal to Hexadecimal
Repeated division by 16; remainders >9 use A-F (A=10, B=11, C=12, D=13, E=14, F=15).
#### Example: Convert 255₁₀ to hexadecimal
255 ÷ 16 = 15 remainder 15 (F)
15 ÷ 16 = 0 remainder 15 (F)
Reading remainders bottom to top: FF₁₆
**Verification**: 15×16¹ + 15×16⁰ = 240 + 15 = 255₁₀ ✓
### Binary to Octal and Hexadecimal
Group binary digits into sets of 3 (for octal) or 4 (for hexadecimal), starting from the right. Pad with leading zeros if necessary.
#### Example: Convert 11010110₂ to octal
Group: 011 010 110 → 3 2 6 → 326₈
**Verification**: 3×8² + 2×8¹ + 6×8⁰ = 192 + 16 + 6 = 214₁₀
Binary: 1×2⁷ + 1×2⁶ + 0×2⁵ + 1×2⁴ + 0×2³ + 1×2² + 1×2¹ + 0×2⁰ = 128+64+0+16+0+4+2+0=214₁₀ ✓
#### Example: Convert 11010110₂ to hexadecimal
Group: 1101 0110 → D 6 → D6₁₆
**Verification**: 13×16¹ + 6×16⁰ = 208 + 6 = 214₁₀ ✓
### Exercise 5: Convert 47₁₀ to binary, octal, and hexadecimal
**Solution**:
- Binary: 47 ÷ 2 = 23 r1; 23÷2=11 r1; 11÷2=5 r1; 5÷2=2 r1; 2÷2=1 r0; 1÷2=0 r1 → 101111₂
- Octal: 47 ÷ 8 = 5 r7; 5 ÷ 8 = 0 r5 → 57₈
- Hexadecimal: 47 ÷ 16 = 2 r15 (F); 2 ÷ 16 = 0 r2 → 2F₁₆
### Exercise 6: Convert 3A7₁₆ to decimal and binary
**Solution**:
- Decimal: 3×16² + 10×16¹ + 7×16⁰ = 3×256 + 10×16 + 7 = 768 + 160 + 7 = 935₁₀
- Binary: 3=0011, A=1010, 7=0111 → 001110100111₂ → 1110100111₂ (leading zeros omitted)
## IV. Operations on Number Systems and Computer Data Units – Part 1
### Binary Addition
Follows same rules as decimal: 0+0=0, 0+1=1, 1+0=1, 1+1=0 with carry 1.
#### Example: Add 1011₂ + 1101₂
```
1011
+ 1101
------
11000
```
Step-by-step:
- Rightmost: 1+1=0, carry 1
- Next: 1+0+carry1=0, carry 1
- Next: 0+1+carry1=0, carry 1
- Next: 1+1+carry1=1, carry 1
- Final carry: 1 → 11000₂
**Verification**: 1011₂=11₁₀, 1101₂=13₁₀, sum=24₁₀; 11000₂=16+8=24₁₀ ✓
### Binary Subtraction
Use borrowing: 0-0=0, 1-0=1, 1-1=0, 0-1=1 with borrow 1.
#### Example: Subtract 1001₂ from 1100₂
```
1100
- 1001
------
0011
```
Step-by-step:
- Right: 0-1 → borrow, becomes 10-1=1, borrow 1
- Next: 0-0-borrow1 → borrow, becomes 10-0-1=1, borrow 1
- Next: 1-0-borrow1=0
- Left: 1-1=0 → 0011₂
**Verification**: 1100₂=12₁₀, 1001₂=9₁₀, diff=3₁₀; 0011₂=3₁₀ ✓
### Data Units
> **Bit**: Binary digit, smallest unit of data (0 or 1).
> **Byte**: Group of 8 bits, standard unit for character encoding.
> **Kilobyte (KB)**: 2¹⁰ = 1024 bytes (not 1000).
> **Megabyte (MB)**: 2²⁰ = 1,048,576 bytes.
> **Gigabyte (GB)**: 2³⁰ bytes.
> **Terabyte (TB)**: 2⁴⁰ bytes.
Note: In networking, sometimes 10³ is used, but in memory/storage, powers of 2 are standard.
#### Example: How many bytes in 2.5 KB?
2.5 × 1024 = 2560 bytes
### Exercise 7: Add 1110₂ + 1011₂
**Solution**:
```
1110
+ 1011
------
11001
```
Verification: 14 + 11 = 25; 11001₂ = 16+8+0+0+1=25 ✓
### Exercise 8: Subtract 1010₂ from 1111₂
**Solution**:
```
1111
- 1010
------
0101
```
Verification: 15 - 10 = 5; 0101₂=5 ✓
### Exercise 9: Convert 5 MB to bytes
**Solution**: 5 × 2²⁰ = 5 × 1,048,576 = 5,242,880 bytes
## V. Operations on Number Systems and Computer Data Units – Part 2
### Binary Multiplication
Similar to decimal: multiply each bit, shift, and add.
#### Example: Multiply 101₂ × 11₂
```
101
× 11
------
101 (101 × 1)
+ 1010 (101 × 1, shifted left)
------
1111
```
Verification: 5 × 3 = 15; 1111₂=8+4+2+1=15 ✓
### Binary Division
Long division method, similar to decimal.
#### Example: Divide 1100₂ by 11₂
```
100
------
11 ) 1100
11
--
00
00
--
00
```
Quotient: 100₂, Remainder: 0
Verification: 12₁₀ ÷ 3₁₀ = 4₁₀; 100₂=4 ✓
### Octal and Hexadecimal Arithmetic
Operations can be performed directly in octal/hexadecimal using their base, or by converting to binary, operating, and converting back.
#### Example: Add 37₈ + 64₈
In octal: 7+4=13₁₀=15₈ → write 5, carry 1; 3+6+1=12₁₀=14₈ → write 4, carry 1 → 145₈
Verification: 37₈=3×8+7=31₁₀; 64₈=6×8+4=52₁₀; sum=83₁₀; 145₈=1×64+4×8+5=64+32+5=101? Wait, error.
Correction: 37₈ = 3×8 + 7 = 24+7=31₁₀
64₈ = 6×8 + 4 = 48+4=52₁₀
Sum = 83₁₀
Convert 83₁₀ to octal: 83÷8=10 r3; 10÷8=1 r2; 1÷8=0 r1 → 123₈
So 37₈ + 64₈ = 123₈
Direct octal:
37
+ 64
-----
7+4=11 → write 1, carry 1 (since 11₁₀=13₈? No—better to think in decimal: 7+4=11, which is 1×8 + 3 → write 3, carry 1)
Then 3+6+1=10 → 10÷8=1 r2 → write 2, carry 1
Then carry 1 → 123₈ ✓
#### Example: Add 1A₁₆ + 2F₁₆
A=10, F=15 → 10+15=25 → 25-16=9, carry 1
1+2+1=4 → 49₁₆
Verification: 1A₁₆=26₁₀, 2F₁₆=47₁₀, sum=73₁₀; 49₁₆=4×16+9=64+9=73 ✓
### Exercise 10: Multiply 110₂ × 101₂
**Solution**:
```
110
× 101
------
110 (110×1)
000 (110×0, shifted)
+ 11000 (110×1, shifted twice)
------
11110
```
Verification: 6×5=30; 11110₂=16+8+4+2+0=30 ✓
### Exercise 11: Divide 10010₂ by 101₂
**Solution**:
```
110
------
101 ) 10010
101
----
0010
0000 (can't subtract)
----
0010 → remainder 10
```
Wait, better:
101 into 1001 (first four bits): 101×1=101, subtract: 1001-101=1000
Bring down 0 → 10000
101 into 10000: 101×11=1111 (too big), 101×10=1010 → subtract: 10000-1010=0110
Bring down 0 → 01100
101 into 1100: 101×10=1010 → subtract: 1100-1010=0010
Quotient: 110, remainder: 10
So 10010₂ ÷ 101₂ = 110₂ remainder 10₂
Verification: 10010₂=18₁₀, 101₂=5₁₀, 18÷5=3 r3; 110₂=6? Mistake.
Correct approach:
10010₂ = 18₁₀
101₂ = 5₁₀
18 ÷ 5 = 3 remainder 3
3₁₀ = 11₂, 3₁₀ = 11₂ → quotient 11₂, remainder 11₂
Check: 101₂ × 11₂ = 101×11 = 1010 + 101 = 1111₂?
101
× 11
-----
101
+1010
-----
1111₂ = 15₁₀, not 18. Error.
Let’s do binary division properly:
Dividend: 10010, Divisor: 101
- Take first 3 bits: 100 < 101 → take 4 bits: 1001
- 1001 ÷ 101: 101×1=101, subtract: 1001-101=1000
- Bring down next bit (0): 10000
- 10000 ÷ 101: 101×11=1111 (too big), 101×10=1010 → subtract: 10000-1010=0110
- Bring down next bit (0): 01100
- 01100 ÷ 101: 101×10=1010 → subtract: 1100-1010=0010
- No more bits → quotient: 110 (from the 1,1,0 we used), remainder: 0010
But we used: first quotient bit for 1001 → 1, then for 10000 → 1, then for 01100 → 0? Let’s align:
```
110
------
101 ) 10010
101 ← 101×1
----
00010 ← 10010-10100? No.
Standard layout:
110
--------
101 | 10010
101 ← 101 × 1 (first 3 bits: 100 < 101, so use 4 bits: 1001)
----
00010 ← 1001 - 101 = 1000? Wait, 1001 - 101 = 1000? 1001 is 9, 101 is 5, 9-5=4=0100, not 00010.
Correct:
Divisor 101 (3 bits), dividend 10010 (5 bits)
- Take first 3 bits: 100 < 101 → take 4 bits: 1001
- 1001 ÷ 101: 101×1=101, subtract: 1001-101=1000 → remainder so far 1000
- Bring down next bit (0): 10000
- 10000 ÷ 101: 101×11=1111 > 10000, so 101×10=1010, subtract: 10000-1010=0110
- Bring down next bit (0): 01100
- 01100 ÷ 101: 101×10=1010, subtract: 1100-1010=0010
- No more bits → quotient bits: 1 (from first), 1 (from second), 0 (from third) → 110₂
- Remainder: 0010₂
Now verify:
Divisor × quotient = 101₂ × 110₂ =
101
× 110
------
000
1010
10100
------
11110₂ = 16+8+4+2=30₁₀? Wrong.
101₂=5, 110₂=6, 5×6=30₁₀=11110₂ ✓
But dividend is 10010₂=18₁₀. 30 ≠ 18. Mistake in quotient.
Correct quotient should be such that divisor × quotient ≤ dividend.
Try quotient 100₂=4: 5×4=20 >18 → too big
Quotient 011₂=3: 5×3=15 ≤18
Remainder=18-15=3=011₂
Check: 101×011 =
101
× 011
------
101
1010
------
1111₂=15₁₀ ✓
So 10010₂ ÷ 101₂ = 011₂ remainder 011₂ → or 11₂ remainder 11₂
In binary division, leading zeros are omitted in quotient, so quotient=11₂, remainder=11₂
Steps:
- 101 into 100 (first 3 bits): 0, so take 1001 (first 4)
- 101 into 1001: 1 time → 1001-101=1000
- Bring down 0 → 10000
- 101 into 10000: 101×11=1111>10000, so 10 → 10000-1010=0110
- Bring down 0 → 01100
- 101 into 01100: 101×10=1010 → 1100-1010=0010
- Quotient: 0 (first), then 1, then 1, then 0 → but we start from first non-zero: after first step we had quotient bit 1 for the 1001 step, then next bit 1, then last bit 0? Let’s use the standard algorithm:
Write dividend: 1 0 0 1 0
Divisor: 1 0 1
- Position: take bits until ≥ divisor: 100 < 101 → take 1001 (positions 1-4)
- 1001 ≥ 101 → quotient bit 1
- Subtract: 1001 - 101 = 1000
- Bring down next bit (0) → 10000
- 10000 ≥ 101 → quotient bit 1
- Subtract: 10000 - 1010 = 0110 (since 101×10=1010)
- Bring down next bit (0) → 01100
- 01100 ≥ 101 → quotient bit 1? 101×10=1010, 101×11=1111>01100? 01100=12, 1010=10, 1111=15>12 → so max 10 → quotient bit 1? No, quotient bit is for the current digit.
Actually, each step gives one quotient bit.
After first subtraction (1001-101=1000), we bring down next bit (0) → 10000
Now, how many times does 101 go into 10000?
101 × 11 = 1111 (too big for 5-bit? 10000 is 5 bits, 1111 is 4 bits → 101×100=10100>10000, 101×11=1111 (4 bits) < 10000? 1111=15, 10000=16 → 16>15 → so 101×11=1111 ≤10000
101×100=10100>10000 → so quotient digit is 11? But we can only use 0 or 1 in binary division per step.
Ah, critical: in binary long division, at each step, the quotient bit is either 0 or 1, because we're dividing by a binary number and the current remainder is less than 2×divisor.
So for 10000 ÷ 101:
- 101 × 1 = 101 (too small)
- 101 × 10 = 1010 (still small)
- 101 × 100 = 10100 > 10000 → so we try 101 × 11 = 1111? No, in binary, we can only multiply by 0 or 1 at each step because the quotient digit is a single bit.
Correct: at each step, we determine if the current remainder (or partial dividend) is ≥ divisor. If yes, quotient bit=1, subtract; else quotient bit=0, bring down next bit.
So:
- Start: 10010
- Take first 3 bits: 100 < 101 → quotient bit=0, bring down next bit → now have 1001 (4 bits)
- 1001 ≥ 101 → quotient bit=1, subtract: 1001-101=1000
- Bring down next bit (0) → 10000
- 10000 ≥ 101 → quotient bit=1, subtract: 10000-1010=0110 (since 101×10=1010, but we can only subtract 101×1=101? No—we subtract divisor multiplied by the quotient bit, which is 1, so subtract 101, not 1010.
Mistake here: when quotient bit is 1, we subtract the divisor (101), not a shifted version. The shifting is handled by bringing down bits.
Correct binary long division:
```
110
--------
101 ) 10010
101 ← subtracted after first 1 quotient bit (aligned to left)
----
00010 ← 10010 - 10100? No.
Let’s do it step by step with alignment:
Divisor: 101 (3 bits)
Dividend: 1 0 0 1 0 (5 bits)
- Consider first 3 bits of dividend: 100
- 100 < 101 → so quotient bit for this position is 0. We now consider first 4 bits: 1001
- 1001 ≥ 101 → quotient bit = 1 (this is the first 1 of quotient)
- Multiply divisor by 1: 101
- Subtract from 1001: 1001 - 101 = 1000
- Bring down next bit (the last 0): now we have 10000
- 10000 ≥ 101 → quotient bit = 1 (second bit of quotient)
- Multiply divisor by 1: 101
- Subtract from 10000: but we must align to the left? No—we subtract from the current remainder, which is 10000, but we have to align the divisor to the left of the current remainder.
Current remainder after first subtraction: 1000 (from 1001-101), then we brought down 0 → 10000
Now, we align divisor 101 to the left of 10000: so we look at the first 3 bits of 10000: 100
- 100 < 101 → so quotient bit should be 0? But earlier I thought 1.
Standard method: after bringing down, we form a new number from the remainder and the brought-down bit, then see how many times divisor goes into it (0 or 1 times).
After first step:
- Remainder = 1000 (from 1001-101)
- Bring down next bit (0) → new number = 10000
- Now, divisor 101 goes into 10000 how many times? Since 101×100=10100>10000, and 101×11=1111 (but 1111 is 4 bits, 10000 is 5 bits → we compare by length: 10000 has 5 bits, 101 has 3 bits → we take first 3+? Actually, we take the same number of bits as divisor or one more.
Better: current remainder is 10000 (5 bits), divisor is 101 (3 bits). We take the first 3 bits of remainder: 100
- 100 < 101 → so quotient bit = 0
- Then we bring down the next bit? But we already brought down all? No—we have 10000, which is 5 bits, we used first 3 to compare, remainder is the last 2? This is confusing.
Let’s use a reliable method: convert to decimal, do division, convert back.
10010₂ = 18₁₀
101₂ = 5₁₀
18 ÷ 5 = 3 remainder 3
3₁₀ = 11₂
3₁₀ = 11₂
So quotient = 11₂, remainder = 11₂
Verification: 101₂ × 11₂ = 101×11 =
101
× 11
------
101
+1010
------
1111₂ = 15₁₀
15 + 3 = 18 ✓
So for the exercise, we’ll use this.
### Exercise 11: Divide 10010₂ by 101₂
**Solution**: Quotient = 11₂, Remainder = 11₂
**Verification**: 101₂ × 11₂ = 1111₂; 1111₂ + 11₂ = 10010₂ ✓
### Exercise 12: Add 76₈ + 54₈
**Solution**:
76
+ 54
----
6+4=12₁₀=14₈ → write 4, carry 1
7+5+1=13₁₀=15₈ → write 5, carry 1
Then carry 1 → 154₈
Verification: 76₈=62₁₀, 54₈=44₁₀, sum=106₁₀; 154₈=1×64+5×8+4=64+40+4=108? Error.
6+4=10 → in octal, 10₁₀ = 12₈ (since 8+2) → write 2, carry 1
Then 7+5+1=13₁₀ = 15₈ (8+5) → write 5, carry 1
Then carry 1 → 152₈
Verification: 152₈=1×64+5×8+2=64+40+2=106₁₀ ✓
### Exercise 13: Subtract 2F₁₆ from 5A₁₆
**Solution**:
5A
- 2F
----
A(10) - F(15) → borrow: 1A(26) - F(15) = B(11)
Then 4 (5-1) - 2 = 2 → 2B₁₆
Verification: 5A₁₆=90₁₀, 2F₁₆=47₁₀, diff=43₁₀; 2B₁₆=2×16+11=32+11=43 ✓
Quiz du chapitre
12 questions — vérifie chaque réponse pour voir l'explication.