C01 Part2
C01 Part2
1
1.8
Number systems
2
Number systems
• A number system is defined as the
representation of numbers by using digits or
other symbols in a consistent manner.
• It is also called the system of numeration.
3
Types of Number Systems
• There are different types of number
systems.
• Four main types are:
– Binary number system (Base - 2)
– Octal number system (Base - 8)
– Decimal number system (Base - 10)
– Hexadecimal number system (Base - 16)
4
Binary Number System
• The numbers in this system have a base of
2.
• The binary number system uses only two
digits: 0 and 1.
• Digits 0 and 1 are called bits and 8 bits
together make a byte. The data in
computers is stored in terms of bits and
bytes.
• For example: 100012 1111012
5
Octal Number System
• The numbers in this system have a base of
8.
• The octal number system uses eight digits:
0,1, 2, 3, 4, 5, 6, 7.
• For example:
358
1418
6
Decimal Number System
• The numbers in this system have a base of
10.
• The octal number system uses ten digits:
0,1, 2, 3, 4, 5, 6, 7, 8, 9.
• The decimal number system is the system
that we generally use to represent numbers
in real life
• For example: 72310 3210 425710
7
Hexadecimal Number System
• The numbers in this system have a base of
16.
• The hexadecimal number system uses
sixteen digits/alphabets:
0,1, 2, 3, 4, 5, 6, 7, 8, 9
A, B, C, D, E, F (the numbers 10-15)
• For example: 7B316 6F16 4B2A16
8
Number systems
9
Conversion Rules of Number Systems
• A number can be converted from one
number system to another number system.
10
Conversion of Number Systems to
Decimal Number System
• Example: Convert 1001112 into the decimal
system.
• Step 1: Identify the • Here, the base of
base of the given 1001112 is 2.
number.
11
Conversion of Number Systems to
Decimal Number System
• Step 2:
– Multiply each digit of the
given number, starting
from the rightmost digit,
with the exponents of the
base.
– The exponents should
start with 0 and increase
by 1 every time as we
move from right to left.
12
Conversion of Number Systems to
Decimal Number System
• Step 3: We just
simplify each
of the above
products and
add them.
1001112 = 3910
13
Conversion of Number Systems to
Decimal Number System
• We can use the following steps to make this
process simplified.
1001112=(1×25)+(0×24)+(0×23)+(1×22)+(1×21)+(1×20)
=(1×32)+(0×16)+(0×8)+(1×4)+(1×2)+(1×1)
=32+0+0+4+2+1
=3910
14
Conversion of Decimal Number
System to Other Number Systems
• Example: Convert 432010 into the octal
system
• Step 1: Identify the • The base of the
base of the required required number is
number. 8
15
Conversion of Decimal Number
System to Other Number Systems
• Step 2:
– Divide the given number by
the base of the required
number and note down the
quotient and the remainder in
the quotient-remainder form.
– Repeat this process (dividing
the quotient again by the
base) until we get the quotient
to be less than the base.
16
Conversion of Decimal Number
Systems to Other Number Systems
• Step 3: The required
number in the octal
number system is
obtained just by
reading all the
remainders and the
last quotient from
bottom to top.
432010=103408
17
Conversion of Decimal Number
Systems to Other Number Systems
• Example: 2020.6562510 → ( ? )16
For Real Part: The real part is 202010
We convert the real part from base 10 to base 16 using division method
same as above.
So, 202010 = 7E416
19
Conversion from One Number
System to Another Number System
• Example: Convert 10101111002 to the
hexadecimal system.
• Step 1: Convert this
number to the decimal
number system as
explained in the
above process.
10101111002 = 70020
10
Conversion from One Number
System to Another Number System
• Step 2: Convert
the above number
(which is in the
decimal system),
into the required 70010 = 2BC16
number system.
10101111002 = 70010
70010 = 2BC16
10101111002=2BC16
21
1.9
Algorithm
22
What is Algorithm?
• An algorithm is a procedure or formula for
solving a problem, based on conducting a
sequence of specified actions.
• For an algorithm to be useful, it must satisfy
five properties:
– The inputs must be specified.
– The outputs must be specified.
– Definiteness.
– Effectiveness.
– Finiteness.
23
What is Algorithm?
• How can we create an algorithm to show the
steps in getting ready for school?
– Get out of bed.
– Take a shower and clean teeth.
– Get dressed.
– Turn on the kettle.
– Put bread in the toaster and turn it on.
– Wait for the kettle to boil and make tea.
– Wait for bread to toast, butter it and add Jam.
– Drink tea and eat toast.
– Gather school books and put in bag.
– Put on shoes and coat.
– Leave the house. 24
What is Algorithm?
• Build a program:
– Problem definition
– Requirement analysis
– Build the algorithms
– Coding
– Testing and debugging
– Maintenance
– Documentation
25
Algorithm development process
• Algorithm development process consists of
five major steps:
– Step 1: Obtain a description of the problem.
– Step 2: Analyze the problem.
– Step 3: Develop a high-level algorithm.
– Step 4: Refine the algorithm by adding more
detail.
– Step 5: Review the algorithm.
26
Presentation of Algorithm
• There are two main ways that algorithms can
be represented:
– Pseudocode
• Pseudocode is a plain language description of the
steps in an algorithm.
• It uses programming-style constructs, but is not
written in an actual programming language.
– Flowchart
• Flowcharts can be used to represent algorithms
visually.
• They use diagrams which use particular symbols to
show the flow of data, processing and input/output
that takes place within a program or task.
27
Pseudocode
• Example 1: Add two numbers entered by
the user
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
28
Pseudocode
• Example 2: Find the largest number among three
numbers
Step 1: Start Step 1: Start
Step 2: Declare variables a,b and c. Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c. Step 3: Read variables a,b and c.
Step 4: Step 4:
if ((a >= b) && (a >= c)) if (a >= b)
Display a is the largest number. if (a >= c)
if ((b >= a) && (b >= c)) Display a is the largest number.
Display b is the largest number. else
if ((c >= a) && (c >= b)) Display c is the largest number
Display c is the largest number. else
Step 5: Stop if (b >= c)
Display b is the largest number.
else
Display c is the largest number.
Step 5: Stop
29
Pseudocode Step 1: Start
Step 2: Declare variables n, i, flag.
31
Flowchart
32
Flowchart Example 5
• Connectors
33
Flowchart
• The Sequence structure
Example 6
34
Flowchart
• The Decision Structure Example 7
35
Flowchart Example 8
36
Flowchart
• Repetition Structures
Example 9
37
Example 10
Flowchart
• Modules
38