Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views29 pages

Foundation Module 2

The document explains binary representation, which is the fundamental way computers store and process data using only 0s and 1s. It covers integer representation, data storage units, character encoding systems like ASCII and Unicode, and the basic architecture of a CPU, including its components and instruction execution process. Overall, it provides a comprehensive overview of how data is represented and processed in computing.

Uploaded by

shilu000001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views29 pages

Foundation Module 2

The document explains binary representation, which is the fundamental way computers store and process data using only 0s and 1s. It covers integer representation, data storage units, character encoding systems like ASCII and Unicode, and the basic architecture of a CPU, including its components and instruction execution process. Overall, it provides a comprehensive overview of how data is represented and processed in computing.

Uploaded by

shilu000001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

text

Your paragraph text yt fb in ln wp


FOUNDATIONS OF COMPUTING:
FROM HARDWARE
MODULE 2
Binary Representation of Data and Numbers

Binary representation is the way computers store and process data using only two digits: 0 and 1. Since computers operate with electrical
signals, which have two states (ON and OFF), binary (also called base-2) is the natural language of computers.

What is Binary Representation?


The binary system is a number system that uses only two digits: 0 and 1.
• Every piece of data in a computer—numbers, text, images, and even videos—is stored in binary.
A bit (binary digit) is the smallest unit of data in computing, representing either 0 or 1.
• Multiple bits are grouped together to form larger units of data.

Why Do Computers Use Binary?


• Computers use electronic circuits, which work with voltage levels:
• 0 → Low voltage (OFF)
• 1 → High voltage (ON)
• Using only two states (binary) makes hardware design simple and reliable.
How Numbers Are Represented in Binary

Just like the decimal system (base-10), binary follows a positional value system.

Each binary digit (bit) represents a power of 2, starting from the rightmost bit:

Binary Place 2³ 2² 2¹ 2⁰

Value 8 4 2 1

Example: Convert (1011)₂ to decimal:

• (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰)


• = (1 × 8) + (0 × 4) + (1 × 2) + (1 × 1)
• =8+0+2+1
= (11)₁₀

Thus, (1011)₂ = (11)₁₀ in decimal.


Converting Decimal to Binary

To convert a decimal number to binary, follow the division-by-2 method.

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

Read the remainders from bottom to top:


(13)₁₀ = (1101)₂

Binary Addition (How Computers Add Numbers)

Binary addition follows simple rules: A B Sum Carry 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1

Example: Add (101)₂ and (011)₂

• 101
• 011

1000 (Binary sum)

Decimal equivalent: 5 + 3 = 8, and (1000)₂ = (8)₁₀, which matches.


Integer Representation in Computers

Computers store and process numbers using binary, but representing integers (both positive and negative) requires specific methods. There are
different ways to store integers in binary, depending on whether they are unsigned (only positive) or signed (both positive and negative).

Unsigned Integer Representation


An unsigned integer is a whole number that does not include negative values. It is represented using standard binary notation.

Example (8-bit unsigned integer representation)

00000000 = 0

00000001 = 1

00000010 = 2

11111111 = 255 (maximum value for 8-bit)


Signed Integer Representation
To represent negative numbers, we need a system that differentiates between positive and negative values. There are three common methods:

Sign-Magnitude Representation

The leftmost bit (MSB - Most Significant Bit) is used as the sign bit:

0 = Positive

1 = Negative

• The remaining bits store the magnitude of the number.

Example (8-bit sign-magnitude representation)

Binary Sign Magnitude Decimal

00000101 0 (positive) 5 +5

10000101 1 (negative) 5 -5
Binary Addition in Two’s Complement
Binary addition follows the same rules as unsigned numbers, even with negative values. Example 1: Adding -3 and +5 in Two’s Complement (8-bit)

Step 1: Represent numbers

-3 → 11111101
+5 → 00000101

Step 2: Add them

11111101 (-3)

• 00000101 (+5)

00000010 (+2, correct result)


Data Storage Units - Bits, Bytes, Kilobytes

Computers store and process data using different units of measurement. These units represent the size of data and determine how much information can be stored or
transmitted.

Basic Units of Data Storage


Bit (Binary Digit)

Smallest unit of data in a computer.

Can be 0 or 1 (binary).

Example: A single bit can store one ON/OFF state.

Byte (B)

1 Byte = 8 Bits.

A byte can store a single character (like 'A' or '5').

• Example:

'A' in ASCII → 01000001 (8 bits).

'B' in ASCII → 01000010 (8 bits).


Larger Units of Data Storage
Since bytes are too small for large data, we use multiples of bytes for storage measurement.

Unit Size

Kilobyte (KB) 1 KB = 1024 Bytes

Megabyte (MB) 1 MB = 1024 KB

Gigabyte (GB) 1 GB = 1024 MB

Terabyte (TB) 1 TB = 1024 GB

Petabyte (PB) 1 PB = 1024 TB

Exabyte (EB) 1 EB = 1024 PB

While computers use powers of 2 (1 KB = 1024 Bytes), some storage devices use decimal-based units (1 KB = 1000 Bytes), especially
in marketing.
Real-World Examples of Data Storage

Data Type Approximate Size

1 Text Character 1 Byte

1 Page of Text ~2 KB

1 MP3 Song ~4 MB

1 HD Movie ~2 GB

1 Hour of 4K Video ~50 GB

Entire Library of Congress ~15 TB

Data Transmission Units


Bits per second (bps): Used for measuring network speeds.
Example: 1 Mbps = 1 Megabit per second (not Megabyte!).
Bytes per second (Bps): Used for file sizes and storage.
ASCII and Unicode – Character Encoding in Computers

Computers represent text using binary (0s and 1s), but to store and process characters like letters, numbers, and symbols, we need
character encoding systems. Two of the most important character encoding schemes are ASCII and Unicode.

What is Character Encoding?


Character encoding assigns a unique binary number to each character (letters, numbers, symbols, etc.) so that computers can
store and process text.

Example:

Character ‘A’ → Binary: 01000001


Character ‘B’ → Binary: 01000010

Without encoding, computers wouldn't understand text data.


ASCII (American Standard Code for Information
Interchange)
What is ASCII?
ASCII is a 7-bit character encoding system developed in the 1960s.
It represents 128 characters (0-127 in decimal).
• Includes:
• Uppercase letters (A-Z)
• Lowercase letters (a-z)
• Numbers (0-9)
• Special symbols (@, #, $, etc.)
• Control characters (Enter, Backspace, etc.)
Example ASCII Table (7-bit)

Character Decimal Binary Hex

A 65 1000001 41

B 66 1000010 42

a 97 1100001 61

b 98 1100010 62

0 48 0110000 30

Space 32 0010000 20

Limitations of ASCII:

Only supports 128 characters (English letters, numbers, and symbols).


No support for other languages like Chinese, Arabic, or Hindi.
Unicode – The Universal Character Encoding
What is Unicode?
Unicode is a universal standard designed to represent all characters from all languages.
Supports over 150,000 characters from different writing systems.
Uses variable-length encoding (UTF-8, UTF-16, UTF-32).

Unicode Encoding Formats

Encoding Bits Per Character Example Use

UTF-8 1 to 4 bytes Web, databases, Linux, modern apps

UTF-16 2 or 4 bytes Windows, Java

UTF-32 4 bytes Scientific applications


Example Unicode Table

Character Unicode (Hex) UTF-8 (Binary)

A U+0041 01000001 (Same as ASCII)

𝄞 (Music Note) U+1D11E 11110000 10011101 10000100


10111110
中 (Chinese) U+4E2D 11100100 10100010 10101101

😊 (Emoji) U+1F60A 11110000 10011111 10011000


10101010
Differences Between ASCII and Unicode

Feature ASCII Unicode

Characters 128 (Standard) / 256 (Extended) Over 150,000

Bit Size 7-bit (Standard), 8-bit (Extended) 8, 16, or 32-bit

Languages Supported English only Supports all languages

Example Characters A-Z, 0-9, @, # Latin, Arabic, Chinese, Emojis


CPU Architecture and Instruction Set: Basic CPU Components

A Central Processing Unit (CPU) is the brain of a computer. It processes instructions, performs calculations, and manages data
movement. The CPU consists of several key components that work together to execute instructions.

Basic CPU Architecture


A CPU consists of three main components:

Arithmetic and Logic Unit (ALU)


Performs mathematical operations (addition, subtraction, multiplication, division).
Executes logical operations (AND, OR, NOT, XOR).
Handles comparisons (greater than, less than, equal to).

🔹 Example:

Adding two numbers: ALU processes 5 + 3 = 8.

Checking conditions: ALU compares if X > Y.


Registers

• Small, fast storage locations inside the CPU.


Hold data, instructions, or addresses temporarily.
• Help the CPU process instructions quickly.

🔹 Types of Registers:

Register Type Purpose

Accumulator (ACC) Stores intermediate results from ALU operations.

Program Counter (PC) Holds the address of the next instruction to execute.

Instruction Register (IR) Stores the current instruction being executed.

Memory Address Register (MAR) Holds the memory address for data access.

Memory Data Register (MDR) Holds data fetched from or stored in memory.

🔹 Example:
When executing ADD A, B, the CPU:

Fetches values of A and B from memory.

Stores them in registers.


The ALU performs A + B.

The result is stored back in a register or memory.


Control Unit (CU)

Manages and coordinates all CPU operations.


Decodes instructions fetched from memory.
Controls data flow between CPU, memory, and I/O devices.

🔹 Functions of the Control Unit:

• Fetches instructions from memory.


• Decodes them into CPU actions.
• Signals the ALU and registers for execution.

Instruction Set and Execution


Instruction Set
The instruction set is a collection of machine-level commands a CPU understands.
Includes instructions for data transfer, arithmetic, logic, and control operations.
• Different CPU architectures (Intel, ARM, RISC-V) have different instruction sets.
Example Instructions (for a simple CPU):
Instruction Meaning

LOAD A, X Load value from memory location X into register A.

ADD A, B Add values in registers A and B.

STORE A, Y Store value in register A to memory location Y.

JUMP X Jump to instruction at address X.


Instruction Format
An instruction format defines how a machine-level instruction is structured. It consists of:

Opcode (Operation Code) – Specifies the operation to be performed (e.g., ADD, MOV, LOAD).

Operands – Specify data or memory locations that the instruction will use.

General Structure of an Instruction

[ Opcode | Operand 1 | Operand 2 ]

Example: ADD A, B

Opcode: ADD (Addition operation)

Operands: A and B (Registers holding values to be added)

Types of Instruction Formats

Instruction Format Description Example

Zero-Address Instructions Uses a stack for operations; no explicit operands. PUSH A, PUSH B, ADD (Result stored on stack)

One-Address Instructions Uses one operand and an accumulator (ACC). ADD X (Adds value at X to ACC)

Two-Address Instructions Uses two operands (destination and source). MOV A, B (Copies value from B to A)

Three-Address Instructions Uses three operands for complex operations. ADD A, B, C (A = B + C)

🔹 Example (Three-Address Format in Assembly Language)

ADD R1, R2, R3 ; R1 = R2 + R3

Opcode: ADD (Addition)

Operands: R1, R2, R3 (Registers storing values)


Assembly Language
(Basics)
Assembly language is a low-level programming language that is easier for humans to read compared to machine code (binary). It uses mnemonics (short codes) for CPU
instructions.

Example Assembly Instructions

MOV A, 5 ; Load value 5 into register A


MOV B, 10 ; Load value 10 into register B
ADD A, B ; Add A and B, store result in A
STORE A, 100 ; Store result in memory location 100

Assembly Instruction Meaning

MOV A, 5 Load value 5 into register A

MOV B, 10 Load value 10 into register B

ADD A, B Add values in A and B, store in A

STORE A, 100 Store the result in memory location 100


Fetch-Execute Cycle (Instruction Execution Process)
The CPU follows a cycle to process and execute instructions stored in memory. This cycle is called the Fetch-Decode-Execute
Cycle.

Steps in the Fetch-Execute Cycle


Fetch – The CPU fetches an instruction from memory.
Decode – The Control Unit deciphers what the instruction means.
Execute – The ALU performs the operation.
Store – The result is stored in memory or registers.
Example: Execution of ADD A,B

1. Fetch:

The Program Counter (PC) holds the memory address of the next instruction.

The instruction is loaded into the Instruction Register (IR).

2. Decode:

The Control Unit (CU) decodes the instruction.

The CPU determines that it must add A and B.

3. Execute:

The ALU performs the addition A + B.

The result is stored in register A.

4. Store:

The updated value in A is saved in the register or memory.

🔹 Graphical Representation of Fetch-Execute Cycle:

1. Fetch → 2. Decode → 3. Execute → 4. Store → (Repeat)


Example: Assembly Program for Addition
Below is a simple assembly program to add two numbers and store the result.

MOV R1, 5 ; Load 5 into Register R1


MOV R2, 10 ; Load 10 into Register R2
ADD R3, R1, R2 ; Add R1 and R2, store result in R3
STORE R3, 200 ; Store result from R3 into memory location 200

Step-by-Step Execution:
MOV R1, 5 → Store 5 in R1.

MOV R2, 10 → Store 10 in R2.

ADD R3, R1, R2 → R3 = R1 + R2 → R3 = 5 + 10 = 15.

STORE R3, 200 → Store 15 in memory location 200.


Summary:

1. Binary Representation of Data and Numbers


Computers use binary (0s and 1s) to represent data.
• Every character, number, and instruction is stored as binary.
2. Integer Representation
Whole numbers are stored in binary using signed (Two’s Complement) and unsigned formats.
Example: 5 in 8-bit binary → 00000101 (Unsigned), 11111011 (-5 in Two’s Complement).

3. Data Storage Units


Basic unit: Bit (0 or 1).
• 1 Byte = 8 bits, 1 KB = 1024 Bytes, 1 MB = 1024 KB, 1 GB = 1024 MB, etc.
4. ASCII and Unicode
ASCII (7-bit, 128 characters) represents English letters, numbers, and symbols.
Unicode (UTF-8, UTF-16, etc.) supports multiple languages and special symbols.
5. Basic CPU Architecture
The CPU consists of ALU (Arithmetic Logic Unit), Registers, and Control Unit (CU).
• ALU performs calculations; Registers store temporary data; CU manages instruction execution.
1. Instruction Set
A set of machine-level commands a CPU understands (e.g., ADD, SUB, MOV).
• Different CPU architectures (RISC, CISC) have different instruction sets.
2. Instruction Format & Assembly Language
Opcode + Operands (e.g., ADD R1, R2 → Add R1 and R2).

• Assembly Language uses mnemonics (human-readable commands).


3. Fetch-Execute Cycle
CPU executes instructions in four steps: Fetch → Decode → Execute → Store.
The Control Unit fetches and decodes, while the ALU executes operations.
4. Memory and Data Storage
CPU interacts with RAM (volatile) and Storage (HDD/SSD, non-volatile).
Registers and Cache provide faster temporary storage.
5. Machine Code vs. High-Level Language
Machine Code (binary) is directly understood by the CPU.
High-Level Languages (Python, C, Java) need a compiler to convert them into machine code.
text

You might also like