Computer
Computer
Programming
1. Introduction
Problem solving is a fundamental skill in computer programming. It involves understanding
a problem, designing a solution, and implementing it using a programming language.
5. Documenting the Code: Write clear and maintainable code with comments.
• int – Integer
• char – Character
• string – Text
1
Operators
• Arithmetic: +, −, ×, ÷, %
Control Structures
• Conditionals: if, else, switch
4. Algorithms
Example Algorithm
Problem: Find the sum of first N natural numbers.
Steps:
1. Input N
2. Initialize sum = 0
3. Loop i from 1 to N :
• sum = sum + i
4. Output sum
5. Flowcharts
Flowcharts are visual representations of algorithms using symbols:
• Oval: Start/End
• Rectangle: Process
• Diamond: Decision
2
6. Pseudocode
Pseudocode uses plain English to describe algorithm steps.
Pseudocode Example
START
SET sum = 0
FOR i = 1 to N
sum = sum + i
END FOR
PRINT sum
END
• Greedy Method
• Dynamic Programming
• Backtracking
• Recursion
9. Example Problems
1. Prime Number Check
2. Palindrome Checker
4. Factorial Calculation
5. Sorting an Array
6. Binary Search
3
10. Best Practices
• Use meaningful variable names.
11. Introduction
Digital fundamentals form the core of computer science, covering the building blocks of
digital systems such as number systems, logic gates, Boolean algebra, and digital circuits.
Conversions
Decimal to Binary
Divide the number by 2 repeatedly and collect remainders in reverse order.
Binary to Decimal
Multiply each bit by 2n (where n is the position from right, starting at 0) and sum all
values.
4
Basic Gates
• AND: Output is 1 only if all inputs are 1.
Derived Gates
• NAND: NOT of AND
• NOR: NOT of OR
Basic Laws
• Identity: A + 0 = A, A · 1 = A
• Null Law: A + 1 = 1, A · 0 = 0
• Complement: A + A = 1, A · A = 0
• Idempotent: A + A = A, A · A = A
De Morgan’s Theorems
De Morgan’s Theorems
A·B =A+B
A+B =A·B
5
Advantages
• Reduces logic complexity
Examples:
• Half Adder
• Full Adder
• Multiplexer (MUX)
• Demultiplexer (DEMUX)
• Encoder
• Decoder
Examples:
• Flip-Flops (SR, D, JK, T)
• Registers
18. Flip-Flops
SR Flip-Flop
Set-Reset flip-flop stores 1 bit of data with S (set) and R (reset) inputs.
6
19. Applications of Digital Circuits
• Digital calculators and computers
• Embedded systems
• Communication devices
• Cache Memory: Fast and small memory between CPU and RAM
7
Memory Access Time Order
Registers ¡ Cache ¡ RAM ¡ HDD
8
26. CPU Organization
Types of CPU Organizations
• Single Accumulator
• Stack Organization
9
31. Pipeline and Parallelism
• Pipelining: Overlapping instruction execution
• Associative Mapping
• Set-Associative Mapping
• Data consistency
• Data integrity
10
• Security and authorization
• Data independence
11
39. Entity-Relationship (ER) Model
Entity: An object with distinct existence (e.g., Student)
Entity Set: A collection of similar types of entities
Attributes: Properties of entities
Relationships: Associations between entities
• One-to-One (1:1)
• One-to-Many (1:N)
• Many-to-Many (M:N)
40. Normalization
Purpose: Eliminate data redundancy and improve data integrity.
Normal Forms
• 1NF: Eliminate repeating groups
12
Examples
Sample SQL
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(100),
Age INT
);
43. Transactions
ACID Properties
• Atomicity: All or nothing
13
45. Database Architecture
• 1-Tier Architecture: Direct interaction
47. Introduction
A computer is an electronic device that accepts data, processes it, stores it, and produces
output. The organization of a computer refers to the operational units and their intercon-
nections that realize the architecture specifications.
14
a. Control Unit (CU)
• Directs the operation of the processor.
• Controls the flow of data between the CPU and other devices.
c. Registers
• Small, high-speed storage locations in the CPU.
• Divided into:
• Computer Architecture: Deals with design, instruction sets, and system-level struc-
ture.
15
50. Bus System
Buses are used for communication between components.
• Registers (fastest)
• Cache Memory
16
54. Conclusion
Computer organization describes how different parts of a computer work together to perform
tasks. Understanding these units is essential to appreciate how data flows through a system
from input to output.
[12pt]article amsmath, amssymb tcolorbox [margin=1in]geometry titlesec
Central Processing Unit (CPU): Detailed Notes
55. Introduction
The Central Processing Unit (CPU) is the main component of a computer that performs
most of the processing inside a computer. It is often referred to as the brain of the
computer.
Key Role
The CPU fetches, decodes, and executes instructions, and coordinates the activities
of all other hardware components.
• Controls the flow of data between the CPU and other devices.
17
56.3. 3. Registers
• Small, fast storage locations inside the CPU.
• Examples:
• Higher clock speed = faster processing (but depends on other factors too).
18
60. Cache Memory
• Small-sized high-speed memory located inside or close to the CPU.
62. Conclusion
The CPU is an essential component that processes all instructions from both hardware and
software. Understanding its internal structure and functioning is critical to understanding
how computers operate at a fundamental level.
[12pt]article amsmath, amssymb tcolorbox [margin=1in]geometry titlesec
Structure of Instructions in CPU
63. Introduction
In a computer, every operation that the CPU performs is controlled by a set of instructions.
These instructions form part of a program and are stored in memory. The CPU fetches and
executes these instructions using its instruction set architecture (ISA).
Instruction Format
An instruction format defines the layout of bits in an instruction word.
19
65. Basic Components of an Instruction
An instruction typically consists of the following fields:
• Operand(s): Specifies the data or the address of data to be used in the operation.
2. One-Address
3. Two-Address
4. Three-Address
20
68. Instruction Cycle
The CPU processes instructions using the following stages:
• Indirect: Address field points to a memory location which contains the actual address.
70. Conclusion
Understanding instruction formats is essential for low-level programming and hardware de-
sign. It affects the efficiency of execution and memory usage. Different architectures (RISC,
CISC) use different instruction formats to optimize performance.
[12pt]article tcolorbox amsmath, amssymb [margin=1in]geometry titlesec
Input and Output Devices: Detailed Notes
71. Introduction
Input and output (I/O) devices are essential hardware components that allow communication
between a user and a computer system.
Definition
Input Devices: Hardware used to send data to a computer.
Output Devices: Hardware used to receive data from a computer.
21
72. Input Devices
These devices are used to input data or control signals to a computer.
72.1. 1. Keyboard
• Most common text input device.
72.2. 2. Mouse
• A pointing device used to interact with graphical user interfaces.
72.3. 3. Scanner
• Converts hard copy images or text into digital form.
72.4. 4. Microphone
• Captures audio signals and converts them into digital data.
72.5. 5. Webcam
• Captures live video and images for video conferencing and security.
72.6. 6. Touchscreen
• Combines display and input interface.
22
73.1. 1. Monitor (Visual Display Unit)
• Displays text, graphics, and videos.
73.2. 2. Printer
• Converts digital documents to hard copy.
73.3. 3. Speaker
• Converts digital audio signals into sound.
73.4. 4. Projector
• Displays computer screen on a large screen or wall.
73.5. 5. Headphones
• Personal audio output device for listening privately.
23
76. Conclusion
I/O devices are critical for enabling interaction with a computer system. Without them,
communication between human users and machines would not be possible.
[12pt]article tcolorbox amsmath, amssymb [margin=1in]geometry titlesec
Computer Memory: Detailed Notes
77. Introduction
Definition
Computer Memory refers to the physical devices used to store data or programs
temporarily or permanently.
• Cache Memory
• Volatile in nature.
24
b) ROM (Read-Only Memory)
• Non-volatile memory.
• Stores firmware and boot instructions.
• Types: PROM, EPROM, EEPROM.
c) Optical Disks
• CD, DVD, Blu-ray.
• Read/write using laser technology.
d) Flash Drives
• Portable and USB-based.
• Used for quick transfers and backups.
25
79.5. 5. Registers
• Smallest and fastest type of memory.
• Non-Volatile: Retains data even when power is off (e.g., ROM, SSD).
82. Conclusion
Memory is crucial for efficient functioning of a computer. Different types of memory are
optimized for different tasks based on speed, volatility, and cost. A well-designed memory
hierarchy ensures fast and reliable computing performance.
[12pt]article tcolorbox amsmath, amssymb [margin=1in]geometry titlesec
Memory Organization: Detailed Notes
83. Introduction
Definition
Memory organization refers to the structure and operation of the memory system that
stores data and instructions in a computer.
26
Memory organization ensures that the processor can quickly access and manipulate data
during computation, balancing speed, cost, and size.
• Non-volatile.
27
85.4. 4. Virtual Memory
• Extends physical memory onto secondary storage.
• Direct Access – Specific blocks of data can be reached directly (e.g., HDD).
• Random Access – Any memory location can be accessed directly (e.g., RAM).
28
88. Memory Management Techniques
88.1. 1. Paging
• Divides memory into fixed-size pages and frames.
88.2. 2. Segmentation
• Divides memory based on logical segments (e.g., code, stack).
• Set Associative Mapping: Cache divided into sets, block maps to any line in a set.
91. Conclusion
Memory organization is crucial for achieving high performance in computer systems. Under-
standing its structure and functioning helps in optimizing data access and storage efficiency.
[12pt]article tcolorbox amsmath, amssymb [margin=1in]geometry titlesec
Backup Devices: Detailed Notes
29
92. Introduction
Definition
Backup devices are hardware storage systems used to create and store copies of digital
data, ensuring data recovery in case of loss, corruption, or disaster.
Data backup is essential for businesses, individuals, and IT systems to safeguard critical
information and maintain data integrity.
30
94.3. 3. Solid State Drives (SSDs)
• Flash-based memory, faster than HDDs.
• No moving parts — more reliable and durable.
• Ideal for quick backups and mobile use.
• More expensive per GB than HDDs.
31
95. Comparison Table
Backup Device Comparison
96. Conclusion
Backup devices are critical for data protection strategies. Selection depends on:
• Volume of data
• Cost constraints
• Duration of storage
• Frequency of backup
Modern setups often use hybrid solutions — combining local and cloud backups — to
ensure both accessibility and resilience.
[12pt]article amsmath tcolorbox [margin=1in]geometry titlesec
Data Representation: Detailed Notes
97. Introduction
Computers store and process data in binary (0s and 1s). All types of data—characters,
integers, and fractions—are internally represented in binary form. Two commonly used
systems in computing are the binary number system and the hexadecimal number
system.
32
• Each digit is called a bit (binary digit).
Example
Binary number 10112 is calculated as:
1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 = 8 + 0 + 2 + 1 = 1110
Example
33
101. 4. Representation of Fractions
Fixed-Point Representation
• Decimal point is fixed at a specific position.
Floating-Point Representation
• Follows IEEE 754 standard.
where s is the sign bit, m is the mantissa (fraction), and e is the exponent.
Extended ASCII
• Uses 8 bits (256 characters).
Unicode
• Supports over 1 million characters.
34
103. 6. Conversions
Binary to Decimal
Multiply each bit by powers of 2 and sum.
Decimal to Binary
Repeatedly divide by 2 and note remainders.
Binary to Hexadecimal
Group binary digits into 4s (from right), then convert each group.
Hexadecimal to Binary
Convert each hex digit into its 4-bit binary equivalent.
104. Conclusion
Understanding how data is represented in computers is fundamental for:
• Efficient computation
• Memory optimization
• Programming logic
105. Introduction
Binary arithmetic is the set of rules and methods used for performing arithmetic operations
on binary numbers. These operations include:
• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Binary Division
35
106. 1. Binary Addition
Binary addition is performed using the following rules:
• 0+1=1
• 1+0=1
Example:
10112 + 11012 =?
1 0 1 1
+ 1 1 0 1
= 1 1 0 0 0
Answer: 110002
• 1−0=1
• 1−1=0
• 0 − 1 = 1 (borrow 1)
Example:
10102 − 00112 =?
1 0 1 0
− 0 0 1 1
= 0 1 1 1
Answer: 01112
36
108. 3. Binary Multiplication
Binary multiplication follows the same logic as decimal multiplication, but with simpler
rules:
• 0×1=0
• 1×0=0
• 1×1=1
Example:
1012 × 112 =?
1 0
1
× 1
1
1 0
1
+ 1 0 1
0
= 1 1 1
1
Answer: 11112
• Repeat.
37
Example:
10102 ÷ 102 =?
Divide 1010 by 10:
102 = 210 , 10102 = 1010 ⇒ 10 ÷ 2 = 5 ⇒ 1012
Answer: 1012
110. Conclusion
Binary arithmetic forms the basis of all arithmetic and logical operations in digital systems.
Understanding how to add, subtract, multiply, and divide binary numbers is crucial for
learning low-level programming, digital logic design, and computer architecture.
[12pt]article amsmath tcolorbox geometry titlesec margin=1in
Signed Arithmetic and Floating Point Representation
+5 = 0101 ⇒ −5 = 1010
38
Subtraction
Rule
A - B is performed as A + (2’s complement of B)
Example:
7 − 5 = 7 + (−5) (Two’s complement of 5 = 1011)
0111 + 1011 = 10010 ⇒ Discard carry: 0010 = 2
39
Advantages
• Ensures maximum precision.
115. Conclusion
Understanding signed and floating-point arithmetic is crucial for numerical computations in
computer systems. These methods enable compact, efficient, and consistent representation
and manipulation of both integers and real numbers.
[12pt]article amsmath,amssymb tikz tcolorbox geometry titlesec margin=1in
Boolean Algebra, Truth Tables and Venn Diagrams
Boolean Variables
Each variable takes value from:
Set B = {0, 1}
Where:
• 0 → False
• 1 → True
Important Laws
Idempotent Laws
A + A = A, A·A=A
40
Complement Laws
A + A = 1, A·A=0
Associative Laws
A + (B + C) = (A + B) + C, A · (B · C) = (A · B) · C
Distributive Laws
A · (B + C) = A · B + A · C
De Morgan’s Laws
A + B = A · B, A·B =A+B
Example: OR Operation
A B A+B
0 0 0
0 1 1
1 0 1
1 1 1
41
Basic Set Operations
• A ∪ B (Union): All elements in A or B.
Example Illustration
[thick] (0,0) circle (1.5); [thick] (1.5,0) circle (1.5); at (-0.8,1.2) A; at (2.3,1.2) B;
119. Application
• Used in designing digital circuits.
• Logic Levels:
2. Boolean Algebra
Boolean algebra is used to describe and simplify digital logic circuits.
42
Basic Operations
Basic Boolean Operations
A · B = AND Operation
A + B = OR Operation
A = NOT Operation
Boolean Laws
• Identity: A + 0 = A, A ·1 = AN ull : A + 1 = 1, A·0=0
3. Logic Gates
Logic gates are the building blocks of digital circuits.
Basic Gates
• AND Gate: Output is 1 if both inputs are 1.
Universal Gates
• NAND: NOT + AND
• NOR: NOT + OR
4. Combinational Circuits
Combinational circuits output based on current inputs.
• Adders:
• Encoders/Decoders
43
5. Sequential Circuits
Sequential circuits depend on current input and previous states.
Flip-Flops
• SR Flip-Flop
• JK Flip-Flop
• D Flip-Flop
• T Flip-Flop
6. Number Systems
Common Number Systems
• Binary (Base 2)
• Octal (Base 8)
7. Logic Simplification
• Boolean Algebra: Apply identities and theorems.
8. Applications
• Digital computers
• Microcontrollers
• Embedded systems
44
• Signal processing
1. Introduction
The block structure of a computer describes the functional organization of a computer sys-
tem. It provides a high-level overview of how different components interact to perform
computations.
computer_block_diagram.png
45
2. Major Components
Main Components of a Computer
• Input Unit
• Memory Unit
• Output Unit
3. Input Unit
• Devices: Keyboard, Mouse, Scanner, Microphone, etc.
• Converts external data to binary signals for the computer to process.
• Transfers input data to the memory or CPU.
Components of CPU
• Arithmetic Logic Unit (ALU): Performs arithmetic (add, subtract) and log-
ical (AND, OR, NOT) operations.
• Control Unit (CU): Directs the operation of the processor. It tells the memory,
ALU, and I/O devices how to respond.
• Registers: Small, fast memory units within the CPU for temporary data stor-
age.
5. Memory Unit
Stores data and instructions temporarily or permanently.
46
6. Output Unit
• Devices: Monitor, Printer, Speakers.
• CPU fetches, decodes, and executes instructions using ALU and registers.
9. Conclusion
Understanding the block structure helps in grasping the fundamental functioning of a com-
puter system. It provides clarity on how data flows and is processed within a digital com-
puter.
[12pt]article amsmath,amssymb tcolorbox graphicx geometry margin=1in Communica-
tion Between Processor and I/O Devices
and Interrupts
1. Introduction
In a computer system, the processor (CPU) must communicate with input/output (I/O)
devices such as keyboards, printers, and storage drives. This communication is essential for
data exchange between the computer and the external environment.
47
2. Methods of Communication
I/O Communication Methods
1. Programmed I/O
2. Interrupt-Driven I/O
• The CPU stops its current task, services the device, and resumes the task.
• CPU initiates the transfer and then performs other tasks while DMA completes it.
3. Interrupts
Definition
An interrupt is a signal sent to the processor by hardware or software indicating an
event that needs immediate attention.
48
3.2 Interrupt Cycle
1. CPU completes current instruction.
5. Executes ISR.
• Non-Vectored Interrupts: CPU uses a fixed ISR address for all interrupts.
5. Summary
• CPU communicates with I/O devices using programmed I/O, interrupts, or DMA.
• Interrupt handling involves saving context, servicing the request, and restoring execu-
tion.
• DMA allows fast and CPU-independent data transfer between memory and I/O de-
vices.
49