Programming for Problem Solving
By
Dr K.Srinivasa Reddy
M Dyva Sugnana Rao
P Kavitha
Y Madan Reddy
Department of Computer Science & Engineering
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Computer:
• The word “computer” comes from the word “compute”,
which means “to calculate”.
• An electronic device that can be programmed to accept data
(input), process it, store it and generate result (output).
• The programmable feature has made it as unique machine
compared to other machines.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Computer System:
• A Computer System primarily comprises of Central Processing Unit (CPU),
memory, input / output devices and auxiliary storage devices. All these components
function together as a single unit to deliver the desired output.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Computer System:
• A computer system comes in various forms and sizes. It can vary from a high-
end server to personal desktop, laptop, tablet computer, or a smartphone.
BVRIT HYDERABAD College of Engineering for Women
Data
What did you observe in the above images?
• Laptop, light, watch, color, men, kid, women, cat, book, cap, gloves, stand, etc..
• Data is the name given to basic facts and entities, as a result of observation,
experience, or experiment.
• The word datum is singular, and data is plural.
BVRIT HYDERABAD College of Engineering for Women
FORMS OF DATA
Numeric 12, 25, 34, 123, 234.454
Character Cat, dog, fish, watch
Sound
Image / Graphic
Video
Scientific and Technical Applications - Numeric Data
Business Applications - Numeric and Character Data
BVRIT HYDERABAD College of Engineering for Women
REPRESENTATION OF DATA
• The form in which data is stored, processed, and transmitted.
• Analog data - continuous - it is 'analogous' to the facts it represents.
• Nature is analog, while data stored in computers is digital.
• Example: The spectrum of colors is a continuous rainbow of an infinite number of
shades.
• Digital data - Discrete and broken up into a limited number of elements.
Analog Digital
• Digitization is the transformation from analog to digital or Digital representation of a
physical item with the goal to digitize and automate processes or workflows.
BVRIT HYDERABAD College of Engineering for Women
COMPUTER AND DATA
• Computer carries out every task with data in some way, without data, it would be
useless.
• Computers are not continuous but finite.
• The 0’s and 1’s used to represent digital data are referred to as binary
digits(bits).
• How much data can be represented? Is there a limit?
• Example: Color image on a computer has a limited number of colors - the
number might be very large, but it is still finite.
• Must understand the representation and organization of data.
BVRIT HYDERABAD College of Engineering for Women
DATA AND INFORMATION
What are products of Data?
• Data is raw, unorganized facts (like crude oil) that needs to be processed.
• Data can be simple, random and useless until it is organized.
• When data is processed, organized, presented in each context to make it useful for humans
and have a logical meaning, called Information.
“You can have data without information, but you cannot have information without data”
-Daniel Keys Moran
BVRIT HYDERABAD College of Engineering for Women
DATA AND INFORMATION
DATA INFORMATION
The history of Covid-19 cases all over the Finding globally COVID-19 cases are rising /
world for the past 100 days. falling.
Collecting the engineering colleges details Finding the colleges which meets your
for admission. requirements.(Region, branch, etc.,)
Students' names in a class are data. Names of students in alphabetic order.
Student's subject marks are data. Percentage of marks, grade and position.
Ticket sales for movie. Sales report by region and venue, to identify
which venue is profitable.
BVRIT HYDERABAD College of Engineering for Women
DATA AND INFORMATION
DATA INFORMATION
Filling out admission form. List of students from city, district etc.
Political surveys How many people are supporting / rejecting a
ruling or opposition party.
Surveys conducted to identify the opinions of How many people like or dislike their
the customers about their products. product? Use information for improving the
quality of product.
Aarogya Setu How many people found positive with in
500m, 1Km, 2Km, etc. How many are using?,
done self assessment? Risk level, etc.
BVRIT HYDERABAD College of Engineering for Women
Basic components of a computer system
Basic Components of a Computer
BVRIT HYDERABAD College of Engineering for Women
Basic components of a computer system
The hearts just like the mother board it allows stuff to flow through it.
The fans like sweat it keeps cooling off the computer just like how sweat
cools down the human body.
Sound card reminds an ear because it allows you to hear things just like an ear.
Eye reminds me to the video card because this allows the user to see.
CPU is like the brain of the computer and vice versa, it allows everything to work
and sends a signal to everything so it can function.
The memory card is just like our memory in our brain.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Memory Unit:
• Internal data storage or primary memory in a computer.
• Every piece of information is encoded as unique combination of 0’s and 1’s. [Bits - Binary Digits]
• Program and data are loaded into the primary memory before processing.
• The memory unit is an ordered sequence of storage cells, each capable of holding a piece of data.
• Each memory cell has a distinct address to which we refer in order to store data into it or retrieve data
from it. These storage cells are called memory cells, or memory locations.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Data Measurement Size
Bit Single Binary Digit (0 or 1)
Nibble 4 bits
Byte (B) 8 bits
Kilobyte (KB) 1,024 Bytes
Megabyte (MB) 1,024 Kilobytes
Gigabyte (GB) 1,024 Megabytes
Terabyte (TB) 1,024 Gigabytes
Petabyte (PB) 1,024 Terabytes
Exabyte (EB) 1,024 Petabytes
Zettabyte (ZB) 1,024 Exabytes
Yottabyte (YB) 1,024 Zettabytes
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Central Processing Unit (CPU):
• Brain of the Computer, responsible for overall
working of all the components of computer.
• The Arithmetic & Logic Unit (ALU): Performs
arithmetic operations (addition, subtraction,
multiplication, and division) and conducts the
comparison of information for logical decisions.
• The Control Unit (CU): Manages the various
components of the computer. It reads and interprets
instructions from memory and transforms them into a Fig. Block Diagram of Computer
series of signals to activate other parts of the
computer, so that program instructions are executed in
the correct order.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Input / Output Devices:
• Input Devices: Used to input data to computer and converts the input to the form which is
usable by the computer.
• Output Devices: The processed results are converted to a form that can be understood easily
by human beings and is displayed.
Fig. I/O Devices
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Memory:
• Human beings memorize many things over a lifetime and recall them to decide or perform
some action.
• Not only relying on memory completely, but humans also make notes and store important data
and information using other media, such as notebook, manual, journal, document, etc.
• Similarly, computers have different types of memories like
• Registers, Cache, RAM, ROM, HDD, CD’s, USB’s, etc.,
• All such memories classified into two categories:
• Primary Memory : Faster in speed, less in size, costlier, and volatile.
• Secondary Memory: Slower in speed, more in size, cheaper, and permanent.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Primary Memory:
• Primary memory is a semiconductor memory and essential component of a computer
system.
• The CPU interacts directly with the primary memory to perform read or write
operation, and CPU cannot work directly on the other type of memory i.e., secondary
memory.
• Program and data are loaded into the primary memory before processing by CPU.
• Types of primary memory:
• Read Only Memory (ROM)
• Random Access Memory (RAM)
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Random Access Memory (RAM) :
• Volatile memory – Contents get destroyed as soon as the power is gone.
• All kinds of intermediate and temporary data used by CPU are contained in RAM i.e.,
programs, data users type goes first into RAM, similarly output comes through RAM.
• Whenever computer is started or a software application is launched, the required program and
data are loaded into RAM for processing.
• Any data present in the secondary memory (HDD, CD etc.,) needs to be brought to RAM and
only it can be used by CPU.
• Usually referred as main memory and it is faster than the secondary memory.
Fig. RAM
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Read Only Memory (ROM) :
• ROM is Read only, Cannot be changed and can be used only by the CPU.
• Non-volatile : Contents are retained even if the power is gone.
• It is used as a small but faster permanent storage for the contents which are rarely changed.
• Present in the form of an Integrated Circuit (IC) chip.
• Purpose: To start the computer i.e., store the Basic Input Output System (BIOS) which is
responsible to make the computer ready for working by the users (called as Booting or
Booting process). Necessary programs and data (part of Operating system) are loaded from
secondary memory to RAM. [Firmware]
Fig. Booting Process Fig. ROM
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Register:
• A register is a small unit of CPU that can store any instruction, data or address for
processor use.
• A special, high-speed storage area within the CPU.
• All data must be represented in a register before it can be processed.
• Example: To multiply two numbers, both numbers must be in registers, and the result
is also placed in a register.
• The register can contain the address of a memory location where data is stored rather
than the actual data itself.
• The number of registers that a CPU has and the size of each (number of bits) help
determine the power and speed of a CPU.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Cache Memory:
• Cache memory is a small-sized type of volatile computer memory that provides high-speed
data access to a processor and stores frequently used computer programs, applications and
data.
• Typically integrated directly with the CPU chip or placed on a separate chip that has a separate
bus interconnect with the CPU.
• Why we need cache, If registers are faster than cache?
• Answer: The size of registers must be compromised as they are located inside the
processor chip so they can't be made large.
Fig. Cache Memory
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Why we need cache when other memories like RAM is available?
• Answer: Cache memory provides faster data storage and access by storing an instance of
programs and data routinely accessed by the processor. Thus, when a processor requests
data that already has an instance in the cache memory, it does not need to go to the main
memory or the hard disk to fetch the data.
• Cache memory increases performance and allows faster retrieval of data.
• It is divided into three levels. — L1, L2, and L3
1. Level 1 (L1) cache, or primary cache, is the smallest and is the first
one to be searched by the CPU. Size: 2KB - 64KB.
2. Level 2 (L2) is searched. L2 cache, or secondary cache, has more
space than L1 cache. Size: 256KB - 512KB.
3. Level 3 (L3) cache, or main memory, is larger and slower than L1
and L2 but is still double the speed of RAM. Size: 1MB – 8MB.
Fig. Levels of Cache Memory
Difference in speed arise due to size and their distance from the processor.
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Secondary Memory :
• Primary memory has limited storage capacity and is either volatile or read-only.
• So, a computer system needs auxiliary or secondary memory to permanently store the data or
instructions for future use.
• These are magnetic memories, non-volatile, larger capacity, slower and cheaper than the main
memory.
• Cannot be accessed directly by the CPU. Contents of secondary storage need to be first
brought into the main memory for the CPU to access.
• In Hard disks, data is stored in the form of sectors, tracks, and cylinders. Every bit is stored
with the help of magnetization of hard disk surface.
• Peripheral device: An input, output, or auxiliary storage device attached to a computer
Fig. Secondary Memory Devices
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Fig. Memory Hierarchy
BVRIT HYDERABAD College of Engineering for Women
Introduction to components of a computer system
Fetch Instruction
• The Control Unit reads the memory address of the next instruction
• This instruction is then read from memory and stored in one of the
registers
• The control unit them points to the next instruction.
Execute Instruction
• The instruction that has been decoded is Decode Instruction
then executed. • The instruction that was moved to the
• Instruction could involve fetching data register is then decoded by the control
from memory and loading / adding it unit, so it understands what must be
into the register. done in the execute cycle
• Writing data to memory. • Any other data the control unit needs in
• Asking the ALU to perform a order to execute this instruction are also
calculation. stored into the register in this step.
• Changing the address of data or
Fetch-Decode-Execute cycle
stopping the program.
BVRIT HYDERABAD College of Engineering for Women
Hardware and Software
Computer Hardware:
• Physical components of a Computer, like CPU, RAM,
Keyboard, Mouse etc.
• A Computer is incapable of performing any task with the
help of hardware alone.
• It requires a set of instructions (called program) to carry
Fig. Senses of Human Body out the specific task.
Computer Software:
• One or more programs along with their documentation.
• Hardware is usually fixed in design
• Software is easily changed
Fig. Human emotions
BVRIT HYDERABAD College of Engineering for Women
Types of Software
• System Software
• Application Software
System Software:
• Software for managing computer hardware behaviour, as to provide basic functionalities that
are required by users, or for other software to run properly.
• Provide a platform to the computer system, where other computer programs can execute.
• It act as a middle layer between the user applications and hardware.
• Types of system software:
System Control Software
System Support Software
System Development Software
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
System Control Software or Operating System (OS):
• A system software acts an interface between a user and computer
hardware, manages resources of the computer, and provide a platform
for storing and executing other software’s.
• Every computer must have at least one OS to run other programs and
not possible for the user to use any computer or mobile device without
having an operating system
• An application like Chrome, MS Office, Games, etc. needs some
environment in which it will run and perform its task.
• The OS helps to communicate with the computer without knowing how
to speak the computer's language.
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
Functions of an Operating System (OS):
Fig. Examples of Operating System:
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
System Support Software:
• Provides routine service functions and other operating services which are designed to assist users
in the maintenance and care of their computer.
• Device Drivers: It is a type of software that controls hardware which is attached to the system.
Hardware devices that need a driver to connect to a system include displays, sound cards, printers,
mice and hard disks.
Fig. Examples of System support software
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
System development software:
You Purpose: Customer
Speaks/Understand Project Work Speaks/Understand
English, Hindi and Mother tongue Location: Japanese Language
Japan
Solution:
• Learn Japanese Language in 30 days.
• Hire a local person as a translator who knows both the languages and convert them.
• Understand the role of translator:
Input Processing Output
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
Are there any challenges in processing? (Yes / No)
Yes
• Understanding of Input Language (Alphabets, words, sentences and its meaning)
• Transforming to Output Language
• Conveying the message in meaningful way
***Translator is a software, not hardware***
BVRIT HYDERABAD College of Engineering for Women
Types of Software - System Software:
System Development Software:
• To use a computer for different purposes, a set of instructions are required to do that work.
• These instructions are written in some English like languages known as High level
languages.
• Computer understands only machine languages (binary language), so it needs translators.
• The language translators that convert programs written in high level languages into
machine language for execution, debugging tools to ensure that the programs are error free.
• Popular language translators include assemblers, compilers, and interpreters.
BVRIT HYDERABAD College of Engineering for Women
Types of Software - Application Software:
• Application Software, or end-user programs or productivity programs are software that helps
the user in performing some specific tasks like writing a letter, listening to music or seeing any
video, doing calculations or even playing games.
• In system software, there is no user interface present whereas in application software the user
interface is present for each software so that users can easily use the software.
• General purpose application software: Software used to perform a broad variety of tasks
that targets the mass market and are used in many ways by different users.
• Examples: Word processor, Spreadsheet, Presentation, database management,
Netflix, PDF, Google Apps, Paint
• Special purpose application software: Software created to execute one specific task.
• Examples: Web Browser, Media Players, Accounting software’s, Science and
Engineering, Education and Entertainment, railway reservation, online admission /
examinations, etc.
• Bespoke Application Software: Tailor made for a specific user and purpose.
BVRIT HYDERABAD College of Engineering for Women
Levels of Programming Languages
Source Code Vs Object Code
Source Code
Source code is in the form of Text form.
Source code is Human Readable Code.
Source code is Generated by Human or Programmer.
Source code is received by Compiler as an Input.
Object Code
Object Code is in the form of Binary Numbers.
Object Code is in Machine Readable formats.
Object Code is Generated by Compiler as a Output.
Language Translator
Language Translators
Compiler
Interpreter
Assembler
Why Language Translators?
Difference between compiler and interpreter
Translator
Language translator is a program that converts the source
code in to the object code.
Why Language Translators?
• Computer only understands object code (machine code).
• It does not understand any source code.
• There must be a program that converts source code in to the
object code
• so that the computer can understand it.
• The language translator is one which does this job.
• The programmer writes the source code and then translator
converts it
• in machine readable format (object code).
Types
Assembler
Compiler
Interpreter
Assembler
Compiler
Compilation Process
Interpreter
Difference between Compiler and Interpreter
Compiler Interpreter
It converts the code line by line.
It converts whole code at a time.
It is slower.
It is faster.
Requires less memory.
Requires more memory.
Errors are displayed for every
Errors are displayed after entire program is instruction
checked. interpreted (if any)
Example: C, C++, JAVA. Example: GW BASIC, Ruby, Python
Number System
• System of writing to express numbers. It is the mathematical notation for representing numbers
of a given set by using digits or other symbols in a consistent manner.
• The value of any digit in a number can be determined by:
• The digit
• Its position in the number
• The base or radix of the number system
(The number of digits or symbols used n the number system)
• Types of Number System:
The four most common number system types are:
1. Decimal number system (Base -10)
2. Binary number system (Base - 2)
3. Octal number system (Base - 8)
4. Hexadecimal number system (Base - 16)
BVRIT HYDERABAD College of Engineering for Women
Number System
System Base Digits Example
Binary 2 0 1 (0101)2
Octal 8 0 1 2 3 4 5 6 7 (76)8
Decimal 10 0 1 2 3 4 5 6 7 8 9 (345)10
Hexadecimal 16 0 1 2 3 4 5 6 7 8 9 A B C D E (24A5)16
Number System Conversion
1. Conversion from Decimal to any base number system
2. Conversion from any Base number system to decimal
3. Any base number system to any base number system
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Case – 1: Decimal integer number – (No fractional part)
Steps:
1. Identify the base of target number system
2. Continually divide the number by its base and with each division, write down the remainder.
3. Read the remainders from bottom to top, which will be the converted result.
Example -1: Convert (25)10 to binary number.
(25)10 ( ???? )2 (25)10 (11001)2
Base = 2, Division Operation Quotient Remainder
25 / 2 12 1 Most Significant Bit (MSB)
12 / 2` 6 0
6/2 3 0 Significant Bit
3/2 1 1
1/2 0 1 Least Significant Bit (LSB)
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Example -2: Convert (25)10 to Octal number.
(25)10 ( ???? )8 (25)10 (31)8
Base = 8, Division Operation Quotient Remainder
25 / 8 3 1 Most Significant Digit (MSD)
3/8 0 3 Least Significant Digit (LSD)
Example -3: Convert (2861)10 to Hexadecimal number.
(2861)10 ( ???? )16 (2861)10 (B2D)16
Base = 16, Division Operation Quotient Remainder
2861 / 16 178 D (13) Most Significant Digit (MSD)
178 / 16 11 2
11 / 16 0 B (11) Least Significant Digit (LSD)
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Case – 2: Decimal integer number with fractional part [Example: 123.345]
Steps:
1. Identify the base of target number system
2. Integer Part:
I. Continually divide the number by its base and with each division, write down the
remainder.
II. Read the remainders from bottom to top, which will be the converted result.
3. Fractional Part:
I. Continually multiply the number by its base and with each multiplication, write down
the carry until the result is zero or when the required number of the equivalent digit is
obtained.
II. Read the carries from top to top, which will be the converted result.
4. Merge the result of Step – 2 and Step -3.
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Example -4: Convert (25.25)10 to binary number.
(25)10 ( ???? )2
Base = 2, Division Operation
Quotient Remainder
for Integer Part
25 / 2 12 1 Base = 2, Multiplication
Result Carry
12 / 2` 6 0 Operation for fraction Part
6/2 3 0 0.25 * 2 0.50 0
3/2 1 1 0.50 * 2 1.0 1
1/2 0 1
(25)10 (11001)2 (0.25)10 (01)2
(25.25)10 (11001.01)2
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Example -5: Convert (25.33)10 to binary number.
(25)10 ( ???? )2
Base = 2, Division Operation Base = 2, Multiplication
Quotient Remainder Result Carry
for Integer Part Operation for fraction Part
25 / 2 12 1 0.33 * 2 0.66 0
12 / 2` 6 0 0.66 * 2 1.32 1
6/2 3 0 0.32 * 2 0.64 0
3/2 1 1 0.64 * 2 1.28 1
1/2 0 1
(0.33)10 (0101)2
(25)10 (11001)2
(25.33)10 (11001.0101)2
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Example -6: Convert (25.33)10 to Octal number.
(25)10 ( ???? )8
Base = 8, Division Operation Base = 8, Multiplication
Quotient Remainder Result Carry
for Integer Part Operation for fraction Part
25 / 8 3 1 0.33 * 8 2.64 2
3/8 0 3 0.64 * 8 5.12 5
0.12 * 8 0.96 0
(25)10 (31)8
0.96 * 8 7.68 7
(0.33)10 (2507)8
(25.33)10 (31.2507)8
BVRIT HYDERABAD College of Engineering for Women
Decimal to Other Number System (Base or Radix):
Example -7: Convert (25.15)10 to Hexa Decimal number.
(25)10 ( ???? )16
Base = 16, Division Base = 16, Multiplication
Quotient Remainder Result Carry
Operation for Integer Part Operation for fraction Part
25 / 16 1 9 0.15 * 16 2.4 2
1 / 16 0 1 0.4 * 16 6.4 6
0.4 * 16 6.4 6
(25)10 (19)16
0.4 * 16 6.4 6
(0.15)10 (2666)16
(25.15)10 (19.2666)8
BVRIT HYDERABAD College of Engineering for Women
Conversion from any base system to decimal
POSITIONAL NUMBERING SYSTEM
Digit Position 5 4 3 2 1 0 -1 -2 -3
Weight b5 b4 b3 b2 b1 b0
. b-1 b-2 b-3
Digit a5 a4 a3 a2 a1 a0 c1 c2 c3
Example - 8: (123456.234)10
POSITIONAL NUMBERING SYSTEM
Digit Position 5 4 3 2 1 0 -1 -2 -3
Decimal Weight 105 104 103 102 101 100 10-1 10-2 10-3
Decimal Digit 1 2 3 4 5 6 2 3 4
.
Value =
100000 20000 3000 400 50 6 0.2 0.03 0.004
Decimal Digit * Decimal Weight
Add the Values 123456 0.234
(123456.234)10
BVRIT HYDERABAD College of Engineering for Women
Conversion from any base system to decimal
Binary to Decimal Conversion:
Example – 9 : (1011)2 = (????)10
POSITIONAL NUMBERING SYSTEM
Digit Position 3 2 1 0
Binary Weight 23 22 21 20
Binary Digit 1 0 1 1
Value =
8 0 2 1
Binary Digit * Binary Weight
Add the Values 11 (8 + 0 + 2 + 1)
(1011)2 = (11)10
BVRIT HYDERABAD College of Engineering for Women
Conversion from any base system to decimal
Binary to Decimal Conversion:
Example – 10 : (1011.11)2 = (????)10
POSITIONAL NUMBERING SYSTEM
Digit Position 3 2 1 0 -1 -2
Binary Weight 23 22 21 20 2-1 2-2
Binary Digit 1 0 1 1 1 1
.
Value =
8 0 2 1 0.5 0.25
Binary Digit * Binary Weight
Add the Values 11 (8 + 0 + 2 + 1) 0.75 (0.5+0.25)
(1011.11)2 = (11.075) 10
BVRIT HYDERABAD College of Engineering for Women
Conversion from any base system to decimal
Octal to Decimal Conversion:
Example – 11 : (126.15)8 = (????)10
POSITIONAL NUMBERING SYSTEM
Digit Position 2 1 0 -1 -2
Octal Weight 82 81 80 8-1 8-2
Octal Digit 1 2 6 1 5
.
Value =
64 16 6 0.125 0.078
Octal Digit * Octal Weight
Add the Values 86 0.203
(126.15)8 = (86.203)10
BVRIT HYDERABAD College of Engineering for Women
Conversion from any base system to decimal
Hexa Decimal to Decimal Conversion:
Example – 11 : (B2D.A2)16 = (????)10
POSITIONAL NUMBERING SYSTEM
Digit Position 2 1 0 -1 -2
Hexa Decimal Weight 162 161 160 16-1 16-2
Hexa Decimal Digit B 2 D A 2
Value = .
Hexa Decimal Digit * Hexa Decimal Weight 2816 32 13 0.0625 0.0078
(A=10, B=11, C=12, D=13, E=14, F=15)
Add the Values 2861 0.0703
(B2D.A2)16 = (2861.0703)10
BVRIT HYDERABAD College of Engineering for Women
Any base number system to any base number system
Binary to Octal Conversion:
Example – 12 : (10010110)2 = (????)8
Method-1: Method-2:
• Convert a binary number into decimal • Using grouping of 3 bits
• Convert decimal to octal number • Take binary number
• Divide the binary digits into groups of
• First convert this into decimal number three (starting from right) for integer part
= (10010110)2 and start from left for fraction part.
= 1x27+0x26+0x25+1x24+0x23+1x22+1x21+0x20 • Convert each group of three binary digits
= 128+0+0+16+0+4+2+0 to one octal digit.
= (150)10
• Convert decimal to octal number • ((010) (010) (110))2 (226)8
= (150)10 (226)8
BVRIT HYDERABAD College of Engineering for Women
Any base number system to any base number system
Binary to Octal Conversion:
Example – 13 : (1010111100)2 = (????)8 Example – 14 : (0110 011.1011)2 = (????)8
((001) (010) (111) (100))2 ((000) (110) (011) . (101)(100))2
(1 2 7 4)8 (0 6 3 . 5 4)8
Octal to Binary Conversion:
Example – 15 : (1274)8 = (????)2
(1274)8 (Expressing each digit as a 03-bit binary representation)
((001) (010) (111) (100))2
(1010111100)2
BVRIT HYDERABAD College of Engineering for Women
Any base number system to any base number system
Binary to Hexadecimal Conversion:
Example – 16 : (10010110)2 = (????)8
Method-1: Method-2:
• Convert a binary number into decimal • Using grouping of 4 bits
• Convert decimal to Hexadecimal number • Take binary number
• Divide the binary digits into groups of
• First convert this into decimal number four (starting from right) for integer part
= (1101010)2 and start from left for fraction part.
= 1x26+1x25+0x24+1x23+0x22+1x21+0x20 • Convert each group of four binary digits
= 64+32+0+8+0+0+2+0 to one hexadecimal digit.
= (106)10
• Convert decimal to octal number • ((0110) (1010))2 (6A)8
= (106)10 (6A)16
BVRIT HYDERABAD College of Engineering for Women
Any base number system to any base number system
Binary to Hexadecimal Conversion:
Example – 17 : (1010101101001)2 = (????)16 Example – 18 : (001100101.110111)2 = (????)16
((0001) (0101) (0110) (1001))2 ((0000) (0110) (0101) . (1101)(1100))8
(1 5 6 9)16 (0 6 5 . D C)16
Hexadecimal to Binary Conversion:
Example – 19 : (1274)16 = (????)2
(1274)16 (Expressing each digit as a 04-bit binary representation)
((0001) (0010) (0111) (0100))2
(1001001110100)2
BVRIT HYDERABAD College of Engineering for Women
Any base number system to any base number system
Octal to Hexadecimal Conversion:
Example – 20 : (345)8 = (????)16 Example – 21 : (1657)8 = (????)16
(011 100 101 )2 (001 110 101 111)2
(0000 1110 0101)2 (0011 1010 1111)2
(E 5)16 (3 A F)16
BVRIT HYDERABAD College of Engineering for Women
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Decimal Number System:
• Positive (+) Numbers or Unsigned numbers:
• Example : 32, 123, 0, +125 [+ symbol is optional]
• Negative (-) Numbers or Signed numbers:
• Examples: -32, -123, -125 [- symbol is mandatory]
Binary Number System:
• In digital circuits there is no provision made to put a ‘+’ or ‘–’ sign to a number, since digital systems operate
with binary numbers that are represented in terms of “0’s” and “1’s”.
• When used together in microelectronics, these “1’s” and “0’s”, called a bit (binary digit), fall into several
range sizes of numbers which are referred to by common names, such as a byte or a word.
• Negative numbers can be distinguishable with the help of extra bit or flag called sign bit or sign flag.
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
• When an integer binary number is
• Positive: The sign is represented by 0 and the magnitude by a positive binary number.
• Negative: The sign is represented by 1 but the rest of the number may be represented in
one of three possible ways:
• Sign-Magnitude method
• 1’s Complement method
• 2’s complement method
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Sign-Magnitude method:
• Simplest and one of the most common methods of representing positive and negative numbers
either side of zero, (0).
• Number is divided into two parts: Sign bit and Magnitude.
• The Most Significant Bit (MSB) is used as sign bit.
• 0 + 1 -
• Magnitude is represented with the binary form of the number to be represented.
Example:
+53 00110101
-53 10110101
Sign Magnitude
Bit
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Sign-Magnitude method:
Unsigned Binary Sign Magnitude Range of Numbers:
0 0000 +0 • For k bits register, MSB will be sign bit and (k-1) bits will
1 0001 +1 be magnitude.
2 0010 +2
• Positive largest number that can be stored is (2(k-1)-1)
3 0011 +3
• Negative lowest number that can be stored is -(2(k-1)-1)
4 0100 +4
5 0101
• Range is -(2(k-1)-1) to (2(k-1)-1) (Inclusive of -0 and +0)
+5
6 0110 +6
• Range of unsigned numbers is 0 to (2k-1)
7 0111 +7 Disadvantage: :
8 1000 -0
• 0 has two different representation one is -0 (e.g., 1000)
9 1001 -1
and second is +0 (e.g., 0000) in four-bit register).
10 1010 -2
11 1011 -3
• Example: 4 – 2 4 0 1 0 0
12 1100 -4 • 4 + (-2) : -2 1 0 1 0
13 1101 -5 • Binary Calculation: -6 against 2 Carry - - - -
14 1110 -6 4 + (-2) 1 1 1 0
15 1111 -7
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
One’s Complement or 1’s Complement:
• Positive numbers are represented in the same way as they are represented in sign magnitude
method.
• Negative numbers are represented by taking the one’s complement (inversion, negation) of the
unsigned positive number.
Example: k= 8
+53 00110101
-53 11001010
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Ones Complement:
Unsigned Binary 1’s Complement Range of Numbers:
0 0000 +0
• For k bits register,
1 0001 +1
2 0010 +2
• Positive largest number that can be stored is (2(k-1)-1)
3 0011 +3 • Negative lowest number that can be stored is -(2(k-1)-1)
4 0100 +4 • Range is -(2(k-1)-1) to (2(k-1)-1) (Inclusive of -0 and +0)
5 0101 +5
Disadvantage: :
6 0110 +6
7 0111 +7
• 0 has two different representation one is -0 (e.g., 1111)
8 1000 -7 and second is +0 (e.g., 0000) in four-bit register).
4 0 1 0 0
9 1001 -6 • Example: 4 – 2
-2 1 1 0 1
10 1010 -5 • 4 + (-2) : 2 Carry 1 1 - - -
11 1011 -4 • Binary calculation: 1 against 2 4 + (-2) 0 0 0 1
12 1100 -3
13 1101 -2
1 - Overflow
14 1110 -1 • To get the correct output add 1 to the result
15 1111 -0
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Addition and Subtraction Using One’s Complement:
• A – B, is the same as saying A + (-B) or -B + A etc.
• The complication of subtracting two binary numbers can be performed by simply using addition.
Example: Perform 115 – 27
• An 8-bit digital system is required to subtract the two numbers 115 and 27 from each other using one’s
complement. So, in decimal this would be: 115 – 27 = 88.
• 11510 (01110011)2 • Overflow or carry bit can be ignored completely or
• 2710 (00011011)2 passed to the next digital section for use in its calculations.
• The 8-bit result is: 01010111 (the overflow “1” cancels
1’s Complement of 2710 (11100100)2 out) and to convert it back from a one’s complement
answer to the real answer, add “1” to the one’s
115 + (– 27) 0 1 1 1 0 0 1 1 complement result, therefore:
+ 11100100 01010111
Overflow 1 0 1 0 1 0 1 1 1 + 1
0 1 0 1 1 0 0 0 (64 + 16 + 8 = 88)
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Two’s Complement or 2’s Complement:
• Positive numbers are represented in the same way as they are represented in sign magnitude
method.
• Negative number is represented using 2’s complement.
• First represent the number with positive sign and then take 2’s complement of that number.
• Two’s complement is one’s complement + 1.
Example:
+53 00110101
-53 11001010 1’s complement
-53 11001011 2’s complement
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Two’s Complement:
Unsigned Binary 1’s Complement 2’s Complement
0 0000 +0 +0
Range of Numbers:
1 0001 +1 +1 • For k bits register,
2 0010 +2 +2 • Positive largest number that can be
3 0011 +3 +3 stored is (2(k-1)-1)
4 0100 +4 +4 • Negative lowest number that can
5 0101 +5 +5 be stored is -(2(k-1))
6 0110 +6 +6 • Range is -(2(k-1)) to (2(k-1)-1)
7 0111 +7 +7 • 0 has only one representation for -
8 1000 -7 -8 0 and +0. Zero (0) is considered as
9 1001 -6 -7
always positive (sign bit is 0) in
10 1010 -5 -6
2’s complement representation.
11 1011 -4 -5
12 1100 -3 -4
• 2’s complement is unique or
13 1101 -2 -3 unambiguous representation.
14 1110 -1 -2
15 1111 -0 -1
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Two’s Complement:
Unsigned Binary Sign Magnitude 1’s Complement 2’s Complement
0 0000 +0 +0 +0
1 0001 +1 +1 +1
2 0010 +2 +2 +2
3 0011 +3 +3 +3
4 0100 +4 +4 +4
5 0101 +5 +5 +5
6 0110 +6 +6 +6
7 0111 +7 +7 +7
8 1000 -0 -7 -8
9 1001 -1 -6 -7
10 1010 -2 -5 -6
11 1011 -3 -4 -5
12 1100 -4 -3 -4
13 1101 -5 -2 -3
14 1110 -6 -1 -2
15 1111 -7 -0 -1
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
Addition and Subtraction Using Two’s Complement:
• A – B, is the same as saying A + (-B) or -B + A etc.
• The complication of subtracting two binary numbers can be performed by simply using addition.
Example: Perform 115 – 27
• An 8-bit digital system is required to subtract the two numbers 115 and 27 from each other using one’s
complement. So, in decimal this would be: 115 – 27 = 88
11510 (01110011)2
2710 (00011011)2
2’s Complement of 2710 (11100101)2 • Overflow or carry bit can be ignored completely or passed
to the next digital section for use in its calculations.
115 – 27 0 1 1 1 0 0 1 1
+ 11100101
Overflow 1 0 1 0 1 1 0 0 0 (64 + 16 + 8 = 88)
BVRIT HYDERABAD College of Engineering for Women
Signed Binary Numbers Representation
1. Find 2’s complement of binary number 10101110.
• Step 1: Find 1’s Complement 01010001
• Step 2: Add 1 to the LSB of Step 1 01010001+1= 01010010
2. Find 2’s complement of binary number 10001.001
• Step 1: Find 1’s Complement 01110.110
• Step 2: Add 1 to the LSB of Step 1 01110.110 +1= 01110.111
1. Find 2’s complement of binary number 10101110 without doing 1’s complement
• Step 1: Move right to left, skip all 0’s from LSB and skip first 1. 10101110
• Step 2: Invert 0 by 1 and 1 by 0 01010010
2. Find 2’s complement of binary number 10001.001
• Step 1: Step 1: Move right to left, skip all 0’s from LSB and skip first 1. 10001.001
• Step 2: Invert 0 by 1 and 1 by 0 01110.111
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
Computer Problem Solving
• A computer is not intelligent. It cannot analyze a problem and produce a solution.
• A human (the programmer) must analyze the problem, develop the instructions for solving the
problem, and the computer will carry out the instructions.
• It is an intricate process requiring much thought, careful planning, logical precision,
persistence, and attention to detail.
• It can be challenging, exiting, and satisfying experience with considerable room for personal
creativity and expression.
• Problem solving and Program writing is a systematic process. It is not all about coding only, it
is not a magic.
• Writing a program for a computer is a two-phase process:
• Problem Solving and
• Implementation.
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
PROBLEM-SOLVING PHASE IMPLEMENTATION PHASE
Analysis and
Specification Concrete Solution
(Program)
General
Solution Test
Verify
Maintenance Phase
Fig. Phases of writing a Program
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
Problem-Solving Phase:
• Analysis and Specification (Problem definition): Understand (define) the problem and
what the solution must do, identify inputs, outputs and processing requirements.
• Concentrate on what must be done rather than how to do it.
• General Solution: Identify and Specify the required data types and the logical sequences
of steps needed to solve the problem and represent them in a particular way (Algorithm,
Pseudo Code, Flow Chart etc.)
• Verify: Follow the steps exactly to see if the solution really does solve the problem.
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
Implementation Phase:
• Concrete Solution (Program): Translate the processing steps in general solution into a program
as per the syntax of the programming language. (Set of instructions)
• Test: Run the program, check it with different types of inputs to verify correctness. If the results
are incorrect for any combination of inputs, review all the problem-solving steps and identify the
mistake. Correct the mistake and again do the implementation phase.
Maintenance Phase
• Modify the program to meet changing requirements or to correct any errors that show up while
using it.
• A program that is implemented in a few months may need to be maintained over a period of many
years.
Programs Life Cycle:
• Together, the problem-solving, implementation, and maintenance phases constitute the program’s
life cycle.
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
The instructions in a programming language reflect the operations a computer can perform:
• Transferring data from one place to another.
• Getting data from an input device (a keyboard or mouse, etc.,)
• Writing data to an output device (a screen).
• Storing data into and retrieve data from its memory and secondary storage
• Comparing data values for equality or inequality and make decisions based on the result.
• Performing arithmetic operations very quickly.
• Branching to a different section of the instructions.
BVRIT HYDERABAD College of Engineering for Women
How Do We Write a Program?
Documentation:
• In addition to solving the problem, implementing the algorithm, and maintaining the
program, writing documentation is an important part of the programming process.
• Documentation includes written explanations of the problem being solved and the
organization of the solution, comments embedded within the program itself, and user
manuals that describe how to use the program.
• Many different people are likely to work on a program over a long period of time. Each of
those people must be able to read and understand the code.
BVRIT HYDERABAD College of Engineering for Women
Algorithm
• Algorithm:
• Step-by-step representation of the solution of the problem, in English like language. Or
• Step-by-step instructions for solving a problem or subproblem in a finite amount of time
using a finite amount of data. Or
• Set of unambiguous steps for solving a problem.
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Algorithm Algorithm
P Q R
C Python Java C Code C Code C Code
Algorithm translated into different languages Algorithm translated by different people
• Differences in implementation of Algorithm:
Example: Writing an essay
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Problem:
Given two variables, a and b, exchange the values assigned to them.
• Analysis: Inputs, outputs, processing
• General Solution: Identify and Specify the required data types and the logical sequences of
steps needed to solve the problem and represent them in a particular way (Algorithm)
Algorithm: Algorithm:
1. Start 1. Start
2. Read the values a and b 2. Read the values a and b
3. Interchange the values 3. Assign a to temporary variable
4. Write the values a and b 4. Assign b to a
5. Stop 5. Assign temporary variable to b
6. Write the values a and b
7. Stop
Steps 3 is not simple, requires more specification.
BVRIT HYDERABAD College of Engineering for Women
Pseudo Code
• More formal representation of Algorithm.
• Each step is very close to the actual programming language representation.
• Each step is well written using operators.
Pseudo Code:
1. Start
2. Read a and b
3. t a
4. a b
5. b t
6. Write a and b
7. Stop
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Problem:
Write an algorithm/pseudo to convert temperature from Fahrenheit to Celsius.
Pseudo Code:
1. Start
2. Read F
3. C (5*(F-32))/9
4. Write C
5. Stop
BVRIT HYDERABAD College of Engineering for Women
Control structures to express algorithms:
SEQUENCE
SELECTION or
BRANCH or
DECISION
LOOP or
REPETETION or
ITERATION
SUB PROGRAM
PROCEDURE
FUNCTION
METHOD
SUB ROUTINE
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Problem:
Write an algorithm/ pseudo code to find whether a given number is odd or even.
Algorithm/ Pseudo code :
1. Start
2. Read N
3. If (N % 2) = 0 then
Write ‘N is even’
else
Write ‘N is odd’
4. Stop
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Problem:
Write an algorithm/ pseudo code to find biggest of two numbers.
Algorithm/ Pseudo code :
1. Start
2. Read a, b
3. If (a > b) then
Write ‘a is big’
else
Write ‘b is big’
4. Stop
BVRIT HYDERABAD College of Engineering for Women
Algorithm
Problem:
Write an algorithm/ pseudo code to find biggest of three numbers.
Algorithm/ Pseudo code :
1. Start
2. Read a, b, c
3. If (a > b) then Assignment:
1. Write algorithm to read three numbers and to
If (a > c) then determine the maximum, second highest and
Write ‘a is big’ the minimum.
else Example:
Write ‘c is big’ Input: 5,9,4
Output: 9,5,4
else
If (b > c) then
Write ‘b is big’ Input: 15,12,24
Output: 24,15,12
else
Write ‘c is big’
4. Stop
BVRIT HYDERABAD College of Engineering for Women
Pseudo Code
Write an algorithm / pseudo code to find the average of n numbers.
Pseudo Code:
1. Start
2. Read n
3. Sum 0
4. i 1
5. while i <= n
6. Read number
7. Sum Sum + number
8. i i + 1
9. end while
10. Average Sum / n
11. Write Average
12. Stop
BVRIT HYDERABAD College of Engineering for Women
Examples: Write an algorithm / pseudo code to
1. Find the sum of first n numbers.
2. Find the sum of ‘n’ numbers.
3. Factorial of a given number
4. Check the given number is Armstrong number or not
5. Reverse of a given number
6. Adam number or not
7. First 10 Fibonacci Series numbers
8. Fibonacci Series below 100
9. Prime number or not
10. Fibonacci Prime
11. Check Perfect number or not
12. Find Armstrong numbers below 1000
13. Find Adam numbers below 1000
14. Find Perfect numbers below 1000 {6, 28, 496} 2p−1(2p − 1) p is prime {Euclid's-Euler
Theorem for even perfect numbers.
BVRIT HYDERABAD College of Engineering for Women
Properties of an Algorithm/Pseudo Code:
• Finiteness: The algorithm must terminate in a finite number of steps.
• Definiteness: Each step must be precisely defined.
• Effectiveness: The operations of the algorithm must be basic enough to be performed, that
they can be done exactly and in finite amount of time.
• Input: An algorithm has zero or more inputs.
• Output: An algorithm produces at least one output.
• Generality: An algorithm must be generic enough to solve all problems of a particular class.
• Correctness: Must give a correct solution.
BVRIT HYDERABAD College of Engineering for Women
Flowchart:
• A flowchart is a graphical representations of steps.
• With proper design and construction, it communicates the steps in a process very effectively
and efficiently.
• It can also be used to define a process or project to be implemented.
• Flowcharts are drawn using simple geometric symbols like rectangle, diamond, oval and small
circle and these symbols are connected by arrows called flow lines.
BVRIT HYDERABAD College of Engineering for Women
Flowchart Symbols:
Terminator: The starting or ending point of the system. Oval
Box: The process / calculation. Rectangle
Data: Input and Output Parallelogram
Decision: Selection or Decision or Branching point Diamond
Flow: Lines represent the flow of the sequence and Arrow
direction of a process.
BVRIT HYDERABAD College of Engineering for Women
Flowchart Symbols:
Merging & Connecting Symbols Input & Output Symbols
Data Symbols Document Symbols
BVRIT HYDERABAD College of Engineering for Women
Examples:
Example-1: Draw flowchart to calculate sum of two Example-2: Draw flowchart to find biggest
numbers. of two numbers.
BVRIT HYDERABAD College of Engineering for Women
Examples:
Example-3: Draw flowchart to find biggest of three Example-4: Draw flowchart to find sum of
numbers. first 100 numbers.
BVRIT HYDERABAD College of Engineering for Women
Examples:
Example-5: Draw flowchart to find factorial of a number.
BVRIT HYDERABAD College of Engineering for Women
Examples:
Raptor Tool To Draw Flowcharts
https://www.programming9.com/raptor-flowcharts
BVRIT HYDERABAD College of Engineering for Women
Advantages of Flowchart:
• Communication: Flowcharts are better way of communicating the logic of a system to all
concerned or involved.
• Effective analysis: With the help of flowchart, problem can be analyzed in more effective
way therefore reducing cost and wastage of time.
• Proper documentation: Program flowcharts serve as a good program documentation, which
is needed for various purposes, making things more efficient.
• Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and
program development phase.
• Proper Debugging: The flowchart helps in debugging process.
• Efficient Program Maintenance: The maintenance of operating program becomes easy with
the help of flowchart. It helps the programmer to put efforts more efficiently on that part
BVRIT HYDERABAD College of Engineering for Women
Disadvantages of Flowchart:
• Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy. This will become a pain for the user, resulting in a waste of
time and money trying to correct the problem
• Alterations and Modifications: If alterations are required the flowchart may require re-
drawing completely. This will usually waste valuable time.
• Special tools: Since it uses special sets of symbols for every action, it is quite a tedious task to
develop a flowchart as it requires special tools to draw the necessary symbols.
• It is just a visualization of a program; it cannot function like an actual program.
BVRIT HYDERABAD College of Engineering for Women
Thankyou
BVRIT HYDERABAD College of Engineering for Women