UNIT 1 Introduction
UNIT 1 Introduction
1. Supercomputers: The fastest and most powerful computers, used for complex
scientific calculations.
2. Mainframes: Large, multi-user computers for bulk data processing and managing
large databases in big organizations.
• Embedded Computers: Specialized computers that are part of a larger device, designed to
perform a specific, dedicated task (e.g., in cars, appliances).
Functional Units of a Computer
• A computer system is made up of several functional units that work together to perform
tasks. These units can be categorized as follows:
1. Input Device
2. Output Device
4. Memory Unit
5. System Bus
1. Input Unit
•Function: Accepts data and instructions from the user or other computers.
It converts this information into a format that the computer can understand.
Examples of Devices: Keyboard, mouse, scanner, microphone.
2. Output Unit
•Function: Displays or presents the results of processing to the user. It converts the
computer's processed data into a human-readable form.
•Examples of Devices: Monitor, printer, speakers.
3. Central Processing Unit (CPU)
The CPU is considered the "brain" of the computer and is responsible for executing instructions and
performing calculations. It consists of three main sub-units:
•Arithmetic and Logic Unit (ALU):
•Function: Performs all arithmetic operations (like addition, subtraction, multiplication, and
division) and logical operations (like comparisons).
•Control Unit (CU):
•Function: Directs and coordinates all the operations of the computer system. It fetches
instructions from memory, decodes them, and sends control signals to other units to execute the
instructions. It acts as the "nerve center" of the computer.
•Registers:
•Function: Small, high-speed storage locations within the CPU that temporarily hold data,
instructions, and addresses that are currently being processed.
4. Memory Unit
•Function: Stores data and instructions that the computer needs for processing. It holds both
the program instructions and the data being manipulated.
•Types:
•Primary Memory (Main Memory): Temporary storage (e.g., RAM) that the CPU can
access directly and quickly. It holds the programs and data currently in use.
•Secondary Memory (Auxiliary Storage): Permanent storage (e.g., hard drives, SSDs,
USB drives) for long-term data and program storage.
5. System Bus
Function: A set of electrical pathways that connect all the functional units. It allows
data, addresses, and control signals to be transmitted between different components of
the computer.
INPUT AND OUTPUT DEVICES
I/O Devices
•Keyboard – Most common device for entering data; available in various key
configurations (84–108 keys).
•Mouse – Moves on-screen cursor; left click = select/move, right click = open menus.
•Joystick – Similar to a mouse; used in CAD and video games; moves in four directions.
•Light Pen – Pen-shaped device for selecting or drawing directly on the screen.
•Scanner – Converts paper documents/images into digital format for editing or storage.
•Bar Code Reader – Scans bar-coded data and converts it into alphanumeric values.
•Web Camera – Captures still images and videos; streams in real-time over the Internet.
Keyboard
Categories of Input Devices: • The most common input device for entering data.
• Typing Keys: The letter keys (A-Z) and number keys (09)
are among these keys.
• Creates images using tiny dots called pixels; more pixels = sharper
image.
Types of Monitors:
• CRT Monitor
• Uses pixels as visual elements.
• Higher resolution when pixels are smaller.
• Flat-Panel Display
• Lighter, thinner, uses less power than CRT.
• Can be wall-mounted or wearable.
• Used in calculators, video games, laptops, and graphical displays
Television
• Types of Printers:
• Impact Printers
• Character Printers – Print one character at a time.
• Line Printers – Print an entire line at once.
• Non-Impact Printers
• Laser Printers – High speed, high quality, uses laser
technology.
• Inkjet Printers – Sprays liquid ink directly onto
paper.
Both Input and Output Devices
• Touchscreen (Input + Output Device)
• Common uses:
• Backing up important data.
• Transferring large files between
computers.
• Expanding storage space.
Types:
• RAM: Main working memory for the operating system and applications.
• Cache: Ultra-fast, small memory for frequently used data, located near the CPU.
• Lower Speed: Slower than primary memory; data must be loaded into RAM first.
• Examples: Hard disk drives (HDDs), solid-state drives (SSDs), USB flash drives.
Key Distinction
• It serves as a non-volatile repository for digital information, meaning it retains the data
even when the computer is turned off.
• Storage devices are crucial for saving the operating system, applications, and user files
for long-term use.
Feature Primary Storage Secondary Storage
To hold data and instructions that the CPU is actively To permanently store the operating system, applications, and
Purpose using for immediate processing. user files for long-term retention.
Volatile (mostly). Data is lost when the computer is Non-volatile. Data is retained even when the computer is
Volatility turned off. turned off.
Slower. Data must be transferred to primary storage first
Extremely Fast. The CPU can access data directly and before the CPU can access it. Access times are in
Speed quickly, typically in nanoseconds. milliseconds.
Limited Capacity. It is a smaller, more expensive type Large Capacity. It provides vast storage space at a lower cost
Capacity of memory. per gigabyte.
Cost Expensive per unit of storage (e.g., per gigabyte). Inexpensive per unit of storage.
RAM (Random Access Memory), Cache Memory, CPU Hard Disk Drives (HDDs), Solid-State Drives (SSDs), USB
Examples Registers. drives, CDs/DVDs.
Essential for the computer to function. The computer Not strictly essential for the computer to function, but vital
Role in System cannot run without primary memory. for storing data and software.
Types of Storage Devices
• Technology: Uses spinning magnetic platters and read/write heads to store data.
• Characteristics: Large storage capacity, low cost per gigabyte, but slower and more
prone to physical damage due to moving parts.
• Characteristics: Significantly faster than HDDs, more durable (no moving parts),
smaller, and lighter. They are generally more expensive per gigabyte.
Optical Storage Devices:
•Technology: Uses a laser to read and write data onto a disc's surface (pits and lands).
•Examples: CDs, DVDs, and Blu-ray discs.
•Characteristics: Removable and portable, often used for media distribution and backups.
Cloud Storage:
•Technology: A remote service that stores data on servers maintained by a third party.
•Characteristics: Accessible from any internet-connected device, scalable, and often used for
backups and file synchronization. It is a service rather than a physical device you own.
Number System Conversion
Example: (153)8
• To convert from octal to binary:
• Break the octal number into digits: 1, 5, 3
• Each octal digit (0-7) corresponds to a 3-bit
• Convert each digit to binary:
binary number.
• 1 in octal = 001 in binary
• For each octal digit, replace it with its
• 5 in octal = 101 in binary
corresponding 3-bit binary equivalent. • 3 in octal = 011 in binary
• It is the fundamental building block of all software, from operating systems and mobile
apps to websites and video games.
1. The Purpose of Code
•Communication: Code acts as a translator between humans and computers. It allows a
programmer to express logical commands in a way that a computer can understand and
execute.
•Instruction: Code is a detailed, step-by-step set of instructions that a computer follows to
perform a specific task. This can be as simple as adding two numbers or as complex as
rendering a 3D environment.
•Problem-Solving: At its core, writing code is about solving problems. Programmers break down
a complex problem into smaller, manageable steps, and then write code to solve each of those
steps.
2. Types of Code
Computer code exists in different forms, each with a specific purpose:
Source Code: This is the human-readable code written by a programmer using a programming
language like Python, Java, or C++. It is the original, raw code that can be viewed and edited.
Machine Code: This is the low-level binary code (0s and 1s) that a computer's central processing
unit (CPU) can directly execute. It is the only language a computer truly understands.
Object Code: This is the output of a compiler, which translates source code into a form that is closer
to machine code. It's an intermediate step in the process of turning human-readable code into an
executable program.
3. How Code Works
The process of turning code into a functioning program involves several steps:
•Writing: A programmer writes source code using a programming language, which has its
specific syntax and rules.
•Translating: Since a computer only understands machine code, the source code must be
translated. This is done by a compiler or an interpreter.
•A compiler translates the entire source code into machine code at once, creating an
executable file.
•An interpreter translates and executes the code line by line, without creating a separate
executable file.
•Executing: The machine code is then executed by the computer's CPU, which performs the
instructed tasks.
4. Code and Programming Languages
Code is always written in a specific programming language. There are thousands of
programming languages, each with its own strengths and use cases.
•High-level languages (like Python, JavaScript, and C++) are designed to be easier for
humans to read and write. They use English-like syntax and have a higher level of abstraction
from the computer's hardware.
•Low-level languages (like Assembly) are closer to machine code and give a programmer
more direct control over the computer's hardware, but are much more difficult to use.
Binary Subtraction and Subtraction
• Binary addition and subtraction are fundamental arithmetic
operations for computers, which operate in the binary number
system (base-2).
• They follow a set of simple rules that are essential for understanding
how computers perform calculations.
Binary Addition
Binary addition is similar to decimal addition, Step-by-step:
but with a base of 2. When the sum of two bits
• Rightmost column (1s place): 1+1=10_2. Write
is greater than 1, a "carry" is generated and down 0 and carry over 1.
moved to the next higher position.
• Next column (2s place): 1+1+1 (the carry) =11_2.
Rules of Binary Addition Write down 1 and carry over 1.
•0+0=0
• Next column (4s place): 0+1+1 (the carry) =10_2.
•0+1=1 Write down 0 and carry over 1.
•1+0=1
• Leftmost column (8s place): 1+1 (the carry)
•1+1=10_2 (This is 0 with a carry of 1) =10_2. Write down 10.
•1+1+1=11_2 (This is 1 with a carry of 1)
• The result is 10010_2. (Decimal equivalent:
Example: Add 1011_2 and 111_2
11+7=18)
1 1 1 (Carry) 1 0 1 1 + 1 1 1 --------- 1 0 0 1 0
Binary Subtraction
Binary subtraction also follows rules similar to decimal Step-by-step:
subtraction, using a "borrow" when a larger digit is
• Rightmost column (1s place): 0−1. You can't do
subtracted from a smaller one.
this directly, so you "borrow" a 1 from the next
• Rules of Binary Subtraction
column. The 1 in the next column becomes a 0.
• 0−0=0 The 0 in the current column becomes a 10_2
• 1−0=1 (which is 2 in decimal). Now, 10_2−1=1. Write
• 1−1=0 down 1.
• 0−1=1 (with a borrow of 1) • Next column (2s place): The digit is now 0 (due
When you "borrow" from the next column, that column's to the borrow). 0−0=0. Write down 0.
digit is reduced by 1. A borrowed '1' from the next
• Leftmost column (4s place): 1−1=0. Write down
column is equivalent to '2' in the current column (since
the base is 2). Example: Subtract 101_2 from 110_2 0.
0 10 (Borrow) 1 1 0 - 1 0 1 --------- 0 0 1 • The result is 001_2, or simply 1_2. (Decimal
equivalent: 6−5=1)
Subtraction with Two's Complement
• For more complex subtractions, especially when • Find the one's complement of the subtrahend by
flipping all the bits (0s become 1s, and 1s become
dealing with signed numbers, computers often use a
0s).
method called two's complement.
• Add 1 to the one's complement to get the two's
• This method converts the subtraction problem into complement.
an addition problem, which is simpler for digital • Add the two's complement of the subtrahend to the
minuend.
circuits to handle.
• If a carry-out is produced from the leftmost bit,
• To subtract a number (the subtrahend) from discard it. The remaining bits are the answer. If
another (the minuend) using two's complement: there is no carry-out, the result is negative and in
two's complement form; you need to take the two's
complement of the result and add a negative sign.
1's and 2's complement of a Binary Number
1's and 2’s Complement of a Binary Number
• Given a binary number s represented as a string. The task is to return its 1's
complement and 2's complement in the form of an array as [one’s Complement, two’s
Complement].
• The 1's complement of a binary number is obtained by flipping all its bits. 0 becomes 1,
and 1 becomes 0. Positive numbers remain unchanged, whereas negative numbers are
represented by taking the 1's complement of their positive counterparts.
+9 is represented as 00001001.
• In 2's complement representation, the Most Significant Bit (MSB) represents the sign.
• Positive numbers are represented the same way as in 1's complement and sign-
bit representation.
• Negative numbers are obtained by taking the 2's complement of their positive
counterparts.
Examples:
Input: s = "0111"
Output: 1001
Explanation: Find 1's complement -> 1000, then add 1 -> 1000 + 1 = 1001
Input: "1100"
Output: 0100
Explanation: Find 1's complement -> 0011, then add 1 -> 0011 + 1 = 0100