0% found this document useful (0 votes)
82 views32 pages

Unit 2 - CFedited

Uploaded by

Meghna Chougule
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)
82 views32 pages

Unit 2 - CFedited

Uploaded by

Meghna Chougule
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/ 32

Introduction

A number is a mathematical value used for counting and measuring objects, and for performing
arithmetic calculations. Numbers have various categories like natural numbers, whole numbers,
rational and irrational numbers, and so on. Similarly, there are various types of number systems that
have different properties, like the binary number system, the octal number system, the decimal
number system, and the hexadecimal number system.
What are Number Systems?
A number system is a system representing numbers. It is also called the system of numeration and it
defines a set of values to represent a quantity. These numbers are used as digits and the most
common ones are 0 and 1, that are used to represent binary numbers. Digits from 0 to 9 are used to
represent other types of number systems.
Definition of Number Systems
A number system is defined as the representation of numbers by using digits or other symbols in a
consistent manner. The value of any digit in a number can be determined by a digit, its position in the
number, and the base of the number system. The numbers are represented in a unique manner and
allow us to operate arithmetic operations like addition, subtraction, and division.
Number system
The base of the number system defines the total number of different digits or symbols available in
the number system.

Two types of number systems are:


 Non-positional number systems
 Positional number systems
1. Non Positional Number System :
Characteristics
 When counting started human beings used their fingers to count. When ten fingers
were not enough he stared using stones and sticks which indicated values.
 Each symbol represents the same value regardless of its position in the number
 For example: Roman Numbers I,II,III,IV,V, VI,VII,VIII, IX,X
Difficulty
• It is difficult to perform arithmetic with such a number system

2. Positional Number System:


Characteristics
 Use only a few symbols called digits
 These symbols represent different values depending on the position they occupy in the
number.
 The value of each digit is determined by:
1. The digit itself
2. The position of the digit in the number
3.The base of the number system(base = total number of digits in the number system)
 The maximum value of a single digit is always equal to one less than the value of the base.

Positional Number System


There are 4 positional number system
• Binary Number system
• Octal Number system
• Decimal Number system
• Hexadecimal Number system
1. Binary Number System
 A positional number system
 Has only 2 symbols or digits (0 and 1). Hence its base = 2
 The maximum value of a single digit is 1 (one less than the value of the base)
 Each position of a digit represents a specific power of the base (2)
 This number system is used in computers
 Example : 101012 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20)
= 16 + 0 + 4 + 0 + 1
= 2110
Bit :
 Bit stands for binary digit
 A bit in computer terminology means either a 0 or a 1
 A binary number consisting of n bits is called an n-bit number
2. Octal Number System
 A positional number system
 Has total 8 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7). Hence, its base = 8
 The maximum value of a single digit is 7 (one less than the value of the base Each
position of a digit represents a specific power of the base (8)
Example
20578 = (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80)
= 1024 + 0 + 40 + 7
= 107110
3. Decimal Number System
 A positional number system
 Has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7,8, 9). Hence, its base = 10
 The maximum value of a single digit is 9 (one less than the value of the base)
 Each position of a digit represents a specific power of the base (10)
 We use this number system in our day-to-day life
Example
258610 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100)
= 2000 + 500 + 80 + 6
=2586
4. Hexadecimal Number System
 A positional number system
 Has total 16 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7,8, 9, A, B, C, D, E, F). Hence its
base = 16
 The symbols A, B, C, D, E and F represent the decimal values 10, 11, 12, 13, 14 and
15 respectively
 The maximum value of a single digit is 15 (one less than the value of the base)
 Each position of a digit represents a specific power of the base (16)
 Since there are only 16 digits, 4 bits (24 = 16) are sufficient to represent any
hexadecimal number in binary
Example
1AF16 = (1 x 162) + (A x 161) + (F x 160)
= 1 x 256 + 10 x 16 + 15 x 1
= 256 + 160 + 15
= 43110

Binary Number to other Bases Conversion


The process of converting a number from binary to decimal is different to the process of converting a
binary number to other bases. Now, let us discuss about the conversion of a binary number to
decimal, octal and Hexa-decimal number systems one by one.
Binary to Decimal Conversion
For converting a binary number into its equivalent decimal number, first multiply the bits of binary
number with the respective positional weights and then add all those products.
Example
Consider the binary number 1101.11.
Mathematically, we can write it as
1101.112 = (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20) + (1 × 2-1) +(1 × 2-2)
⇒ 1101.112 = 8 + 4 + 0 + 1 + 0.5 + 0.25 = 13.75
⇒ 1101.112 = 13.7513.7510
Therefore, the decimal equivalent of binary number 1101.11 is 13.75.
Binary to Octal Conversion
We know that the bases of binary and octal number systems are 2 and 8 respectively. Three bits of
binary number is equivalent to one octal digit, since 23 = 8.
Follow these two steps for converting a binary number into its equivalent octal number.
• Start from the binary point and make the groups of 3 bits on both sides of binary
point. If one or two bits are less while making the group of 3 bits, then include
required number of zeros on extreme sides.
• Write the octal digits corresponding to each group of 3 bits.
Example
Consider the binary number 101110.01101.
Step 1 − Make the groups of 3 bits on both sides of binary point.
101 110.011 01
Here, on right side of binary point, the last group is having only 2 bits. So, include one zero on
extreme side in order to make it as group of 3 bits.
⇒ 101 110.011 010
Step 2 − Write the octal digits corresponding to each group of 3 bits.
⇒ 101110.0110102 = 56.328
Therefore, the octal equivalent of binary number 101110.01101 is 56.32.

Binary to Hexa-Decimal Conversion


We know that the bases of binary and Hexa-decimal number systems are 2 and 16 respectively. Four
bits of binary number is equivalent to one Hexa-decimal digit, since 24 = 16.
Follow these two steps for converting a binary number into its equivalent Hexa-decimal number.
• Start from the binary point and make the groups of 4 bits on both sides of binary
point. If some bits are less while making the group of 4 bits, then include required
number of zeros on extreme sides.
• Write the Hexa-decimal digits corresponding to each group of 4 bits.
Example
Consider the binary number 101110.01101
Step 1 − Make the groups of 4 bits on both sides of binary point.
10 1110.0110 1
Here, the first group is having only 2 bits. So, include two zeros on extreme side in order to make it
as group of 4 bits. Similarly, include three zeros on extreme side in order to make the last group also
as group of 4 bits.
⇒ 0010 1110.0110 1000
Step 2 − Write the Hexa-decimal digits corresponding to each group of 4 bits.
⇒ 0010 1110.011010002 = 2E.6816
Therefore, the Hexa-decimal equivalent of binary number 101110.01101 is 2E.68.

Octal Number to other Bases Conversion


The process of converting a number from octal to decimal is different to the process of converting an
octal number to other bases. Now, let us discuss about the conversion of an octal number to decimal,
binary and Hexa-decimal number systems one by one.
Octal to Decimal Conversion
For converting an octal number into its equivalent decimal number, first multiply the digits of octal
number with the respective positional weights and then add all those products.
Example
Consider the octal number 145.23.
Mathematically, we can write it as
145.238 = (1 × 82) + (4 × 81) + (5 × 80) + (2 × 8-1) + (3 × 8-2)
⇒ 145.238 = 64 + 32 + 5 + 0.25 + 0.05 = 101.3
⇒ 145.238 = 101.310
Therefore, the decimal equivalent of octal number 145.23 is 101.3.
Octal to Binary Conversion
The process of converting an octal number to an equivalent binary number is just opposite to that of
binary to octal conversion. By representing each octal digit with 3 bits, we will get the equivalent
binary number.
Example
Consider the octal number 145.23.
Represent each octal digit with 3 bits.
145.238 = 001100101.0100112
The value doesn‟t change by removing the zeros, which are on the extreme side.
145.238 = 1100101.0100112
Therefore, the binary equivalent of octal number 145.23 is 1100101.010011.
Octal to Hexa-Decimal Conversion
Follow these two steps for converting an octal number into its equivalent Hexa-decimal number.
• Convert octal number into its equivalent binary number.
• Convert the above binary number into its equivalent Hexa-decimal number.
Example
Consider the octal number 145.23
In previous example, we got the binary equivalent of octal number 145.23 as 1100101.010011.
By following the procedure of binary to Hexa-decimal conversion, we will get
1100101.0100112 = 65.4C16
⇒145.238 = 65.4C16
Therefore, the Hexa-decimal equivalent of octal number 145.23 is 65.4C.

Decimal Number to other Bases Conversion


If the decimal number contains both integer part and fractional part, then convert both the parts of
decimal number into other base individually. Follow these steps for converting the decimal number
into its equivalent number of any base „r‟.
• Do division of integer part of decimal number and successive quotients with base „r‟
and note down the remainders till the quotient is zero. Consider the remainders in
reverse order to get the integer part of equivalent number of base „r‟. That means, first
and last remainders denote the least significant digit and most significant digit
respectively.
• Do multiplication of fractional part of decimal number and successive fractions with
base „r‟ and note down the carry till the result is zero or the desired number of
equivalent digits is obtained. Consider the normal sequence of carry in order to get the
fractional part of equivalent number of base „r‟.

Decimal to Binary Conversion


The following two types of operations take place, while converting decimal number into its
equivalent binary number.
• Division of integer part and successive quotients with base 2.
• Multiplication of fractional part and successive fractions with base 2.
Example
Consider the decimal number 58.25. Here, the integer part is 58 and fractional part is 0.25.
Step 1 − Division of 58 and successive quotients with base 2.
Operation Quotient Remainder
58/2 29 0 LSB
29/2 14 1
14/2 7 0
7/2 3 1
3/2 1 1
½ 0 1MSB

⇒5810 = 1110102
Therefore, the integer part of equivalent binary number is 111010.
Step 2 − Multiplication of 0.25 and successive fractions with base 2.
Operation Result Carry
0.25 x 2 0.5 0
0.5 x 2 1.0 1
- 0.0 -

⇒.2510 = .012
Therefore, the fractional part of equivalent binary number is .01
⇒58.2510 = 111010.012
Therefore, the binary equivalent of decimal number 58.25 is 111010.01.

Decimal to Octal Conversion


The following two types of operations take place, while converting decimal number into its
equivalent octal number.
• Division of integer part and successive quotients with base 8.
• Multiplication of fractional part and successive fractions with base 8.
Example
Consider the decimal number 58.25. Here, the integer part is 58 and fractional part is 0.25.
Step 1 − Division of 58 and successive quotients with base 8.
Operation Quotient Remainder
58/8 7 2
7/8 0 7
⇒5810 = 728
Therefore, the integer part of equivalent octal number is 72.
Step 2 − Multiplication of 0.25 and successive fractions with base 8.
Operation Result Carry
0.25 x 8 2.00 2
- 0.00 -
⇒ .2510 = .28
Therefore, the fractional part of equivalent octal number is .2
⇒ 58.2510 = 72.28
Therefore, the octal equivalent of decimal number 58.25 is 72.2.
Decimal to Hexa-Decimal Conversion
The following two types of operations take place, while converting decimal number into its
equivalent hexa-decimal number.
• Division of integer part and successive quotients with base 16.
• Multiplication of fractional part and successive fractions with base 16.
Example
Consider the decimal number 58.25. Here, the integer part is 58 and decimal part is 0.25.
Step 1 − Division of 58 and successive quotients with base 16.
Operation Quotient Remainder
58/16 3 10=A
3/16 0 3
⇒ 5810 = 3A16
Therefore, the integer part of equivalent Hexa-decimal number is 3A.
Step 2 − Multiplication of 0.25 and successive fractions with base 16.
Operation Result Carry
0.25 x 16 4.00 4
- 0.00 -
⇒.2510 = .416
Therefore, the fractional part of equivalent Hexa-decimal number is .4.
⇒58.2510 = 3A.416
Therefore, the Hexa-decimal equivalent of decimal number 58.25 is 3A.4.

Hexa-Decimal Number to other Bases Conversion


The process of converting a number from Hexa-decimal to decimal is different to the process of
converting Hexa-decimal number into other bases. Now, let us discuss about the conversion of Hexa-
decimal number to decimal, binary and octal number systems one by one.
Hexa-Decimal to Decimal Conversion
For converting Hexa-decimal number into its equivalent decimal number, first multiply the digits of
Hexa-decimal number with the respective positional weights and then add all those products.

Example
Consider the Hexa-decimal number 1A5.2
Mathematically, we can write it as
1A5.216 = (1 × 162) + (10 × 161) + (5 × 160) + (2 × 16-1)
⇒ 1A5.216 = 256 + 160 + 5 + 0.125 = 421.125
⇒ 1A5.216 = 421.12510
Therefore, the decimal equivalent of Hexa-decimal number 1A5.2 is 421.125.

Hexa-Decimal to Binary Conversion


The process of converting Hexa-decimal number into its equivalent binary number is just opposite to
that of binary to Hexa-decimal conversion. By representing each Hexa-decimal digit with 4 bits, we
will get the equivalent binary number.
Example
Consider the Hexa-decimal number 65.4C
Represent each Hexa-decimal digit with 4 bits.
65.4C6 = 01100101.010011002
The value doesn‟t change by removing the zeros, which are at two extreme sides.
⇒ 65.4C16 = 1100101.0100112
Therefore, the binary equivalent of Hexa-decimal number 65.4C is 1100101.010011.
Hexa-Decimal to Octal Conversion
Follow these two steps for converting Hexa-decimal number into its equivalent octal number.
• Convert Hexa-decimal number into its equivalent binary number.
• Convert the above binary number into its equivalent octal number.
Example
Consider the Hexa-decimal number 65.4C
In previous example, we got the binary equivalent of Hexa-decimal number 65.4C as
1100101.010011.
By following the procedure of binary to octal conversion, we will get
1100101.0100112 = 145.238
⇒65.4C16 = 145.23𝟖
Therefore, the octal equivalent of Hexa-decimal number 65.4C is 145.23.

Computer Codes
Computer Data:
1. Numeric Data consists of only numbers 0, 1, 2, …, 9
2. Alphabetic Data consists of only the letters A, B, C,…, Z, in both uppercase and lowercase,
and blank character
3. Alphanumeric Data is a string of symbols where a symbol may be one of the letters A, B, C,
…, Z, in either uppercase or lowercase, or one of the digits 0,1, 2, …, 9, or a special
character, such as + - * / , . ( ) = etc.
Computer Codes:
 Computer codes are used for internal representation of data in computers
 As computers use binary numbers for internal data representation, computer codes use binary
coding schemes
 In binary coding, every symbol that appears in the data is represented by a group of bits
 The group of bits used to represent a symbol is called a byte
 As most modern coding schemes use 8 bits to represent a symbol, the term byte is often used
to mean a group of 8 bits
Commonly used computer codes are BCD, EBCDIC, Gray and ASCII
1. BCD
 BCD stands for Binary Coded Decimal
 It is one of the early computer codes
 It uses 4 bits to represent a symbol

Advantages of BCD Codes


 It is very similar to decimal system.
 We need to remember binary equivalent of decimal numbers 0 to 9 only.
Disadvantages of BCD Codes
 The addition and subtraction of BCD have different rules.
 The BCD arithmetic is little more complicated.
 BCD needs more number of bits than binary to represent the decimal number. So
BCD is less efficient than binary.

2. Gray Code
o It is the non-weighted code and it is not arithmetic codes. That means there are no specific
weights assigned to the bit position.
o It has a very special feature that, only one bit will change each time the decimal number is
incremented as shown in fig.
o As only one bit changes at a time, the gray code is called as a unit distance code.
o The gray code is a cyclic code.
o Gray code cannot be used for arithmetic operation

3. ASCII:
 ASCII stands for American Standard Code for Information Interchange.
 ASCII is of two types – ASCII-7 and ASCII-8
 ASCII-7 uses 7 bits to represent a symbol and can represent 128 (27) different
characters
 ASCII-8 uses 8 bits to represent a symbol and can represent
 (28) different characters
 First 128 characters in ASCII-7 and ASCII-8 same
Coding of numeric and alphabetic characters in ASCII

ASCII-7 coding scheme


Example
Write binary coding for the word BOY in ASCII-7. How many bytes are required for this
representation?
Solution:
B = 1000010 in ASCII-7 binary notation
O = 1001111 in ASCII-7 binary notation
Y = 1011001 in ASCII-7 binary notation
Hence, binary coding for the word BOY in ASCII-7 will be
1000010 1001111 1011001
B O Y
Since each character in ASCII-7 requires one byte for its representation and there are 3 characters in
the word BOY, 3 bytes will be required for this representation
ASCII-8 coding scheme
Example
Write binary coding for the word SKY in ASCII-8. How many bytes are required for this
representation?
Solution:
S = 01010011 in ASCII-8 binary notation
K = 01001011 in ASCII-8 binary notation
Y = 01011001 in ASCII-8 binary notation
Hence, binary coding for the word SKY in ASCII-8 will be
01010011 01001011 01011001
S K Y
Since each character in ASCII-8 requires one byte for its representation and there are 3 characters in
the word SKY, 3 bytes will be required for this representation

Boolean Algebra
 An algebra that deals with binary number system
 George Boole (1815-1864), an English mathematician, developed it for:
 Simplifying representation
 Manipulation of propositional logic
 In 1938, Claude E. Shannon proposed using Boolean algebra in design of relay switching
circuits
 Provides economical and straightforward approach
 Used extensively in designing electronic circuits used in computers
Fundamental Concepts of Boolean Algebra
 Use of Binary Digit
 Boolean equations can have either of two possible values, 0 and 1
 Logical Addition
 Symbol „+‟, also known as „OR‟ operator, used for logical addition. Follows law of
binary addition
 Logical Multiplication
 Symbol „.‟, also known as „AND‟ operator, used for logical multiplication.
Follows law of binary multiplication
 Complementation
 Symbol „~‟, also known as „NOT‟ operator, used for complementation. Follows law
of binary compliment

Operator Precedence
 Each operator has a precedence level
 Higher the operator‟s precedence level, earlier it is evaluated
 Expression is scanned from left to right
 First, expressions enclosed within parentheses are evaluated
 Then, all complement (NOT) operations are performed
 Then, all „×‟ (AND) operations are performed
 Finally, all „+‟ (OR) operations are performed
Postulates of Boolean Algebra

The Principle of Duality


There is a precise duality between the operators . (AND) and + (OR), and the digits 0 and 1.
For example, in the table below, the second row is obtained from the first row and vice versa simply
by interchanging „+‟ with „.‟ and „0‟ with „1‟
Column 1 Column 2 Column 3
Row 1 1+1=1 1+0=0+1=1 0+0=0
Row 2 0 ×0 = 0 0 ×1 = 1 ×0 = 0 1 ×1 = 1

Therefore, if a particular theorem is proved, its dual


theorem automatically holds and need not be proved separately

Methods of Proving Theorems


The theorems of Boolean algebra may be proved by using one of the following methods:
1. By using postulates to show that L.H.S. = R.H.S
2. By Perfect Induction or Exhaustive Enumeration method where all possible combinations of
variables involved in L.H.S. and R.H.S. are checked to yield identical results
3. By the Principle of Duality where the dual of an already proved theorem is derived from the
proof of its corresponding pair

Proving a Theorem by Using Postulates (Example)


Theorem:
x+x·y=x
Proving a Theorem by Perfect Induction (Example)
Theorem:
x+x·y=x
X y x· y x+x· y
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1

Boolean Functions
 A Boolean function is an expression formed with:
 Binary variables
 Operators (OR, AND, and NOT)
 Parentheses, and equal sign
 The value of a Boolean function can be either 0 or 1
 A Boolean function may be represented as:
 An algebraic expression, or
 A truth table
Representation as an Algebraic Expression
W=X+
Y ·Z
 Variable W is a function of X,Y and Z ,can also be written as W = f (X, Y, Z)
 The RHS of the equation is called an expression
 The symbols X, Y, Z are the literals of the function
 For a given Boolean function, there may be more than one algebraic expressions

Representation as a Truth Table


X Y Z W
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1

 The number of rows in the table is equal to 2n, where n is the number of literals in the
function
 The combinations of 0s and 1s for rows of this table are obtained from the binary numbers by
counting from 0 to 2n - 1
Boolean Operators
Boolean operators are words that connect search terms (keywords) to create a logical phrase that a
database can understand. They allow you to create a complex search that could include multiple
concepts and alternative keywords.
Boolean Operator What it Does How to use
AND Finds items that use both keywords. adult learning AND online courses
OR Finds items that use either of the keywords. adult learners OR adult students
NOT Excludes articles that use the keyword. NOT masters programs
Logic Gates
 Logic gates are electronic circuits that operate on one or more input signals to produce
standard output signal
 Are the building blocks of all the circuits in a computer
 Some of the most basic and useful logic gates are AND, OR, NOT, NAND ,NOR, XOR and
XNOR gates.
 Most electronic devices we use today will have some form of logic gates in them. For
example, logic gates can be used in technologies such as smartphones, tablets or within
memory devices.

AND Gate (Block Diagram Symbol and Truth Table)


 An AND gate has two or more inputs and one output.
 The output of AND gate is 1 only when input A and input B are both 1.
 Physical realization of logical Multiplication (AND Operation) Y= A.B

OR Gate (Block Diagram Symbol and Truth Table)


 An OR gate has two or more inputs with one output. The output is 1 when either input A or
input B or both are 1s, that is, if any of the input is high, the output is high.
 Physical realization of logical addition (OR) operation Y= A+B
NOT Gate (Block Diagram Symbol and Truth Table)

This is the most basic gate, with one input and one output. It produces a „1‟ output if the
input is „0‟ and vice-versa. That is, it produces an inverted version of the input at its
output.

NAND Gate (Block Diagram Symbol and Truth Table)

This is an AND gate followed by a NOT gate. If inputs A and B are both „1‟, the output Y
is not „1‟. The gate gets its name from this NOT AND behavior.
NAND gates are also called Universal Gates since by using these gates you can realize
other basic gates like OR, AND and NOT.
NOR Gate (Block Diagram Symbol and Truth Table)

It has two or more inputs and one output. A NOT- operation applied after OR gate gives a
NOT-OR gate (or simply NOR gate). Its output Y is „1‟ only when both inputs A and B
are „0‟, i.e., neither one input nor the other is „1‟.

NOR gates are considered as universal gates because you can obtain all the gates like
AND, OR, NOT by using only NOR gates

XOR gate:
An XOR gate is a two-input single-output logic gate whose output is assumed to be HIGH(one) only
when one of its inputs is HIGH(one).
XNOR Gate: An XNOR gate is a two-input single-output logic gate whose output is high when
both inputs are set to high(1).

Logic Circuits
 When logic gates are interconnected to form a gating / logic network, it is known as a
combinational logic circuit
 The Boolean algebra expression for a given logic circuit can be derived by systematically
progressing from input to output on the gates
 The three logic gates (AND, OR, and NOT) are logically complete because any Boolean
expression can be realized as a logic circuit using only these three gates
Finding Boolean Expression of a Logic Circuit (Example 1)
Finding Boolean Expression of a Logic Circuit (Example 2)

Constructing a Logic Circuit from a Boolean Expression (Example 1)


Boolean Expression = A.B+C
Constructing a Logic Circuit from a Boolean Expression (Example 2)

Computer Languages
There are mainly three different languages with the help of which we can develop computer
programs. And they are:
• Machine Level language
• Assembly Level Language and
• High-Level Language
Machine Level Language
The computer can understand only the language of Digital Electronics. Digital Electronics deals with
the presence and absence of voltages. Within the computer there are two logics can play their role.
These logics are −
• Positive Logic − Here presence of voltage will be denoted by 1 and absence of
voltage will be denoted by 0
• Negative Logic − Here presence of voltage will be denoted by 0 and absence of
voltage will be denoted by 1
• But obviously, the computer can follow any one of the logic at a time, not both the logics
simultaneously.
• To make the computer understand, a program can be written using only 0s and 1s.
• The data can also be specified and represented using only 0s and 1s.
• Such a program is called Machine Language program. Machine language was the first in the
evolution of computer programming languages. Computer directly understands a program
written in the machine language.
• So as a result, the machine language program does not require any translator to convert from
one form to another. In fact, even to this day, basically, computers understand only the 0s and
1s.

Assembly Level Language


• Assembly language uses mnemonics or symbolic instructions in place of a sequence of 0s and
1s.
• Example: we can consider that to add register A and B in a particular computer, assembly
language uses the mnemonic „ADD B‟ in place of 10001111. In assembly language, we use
symbolic names to denote addresses and data.
• Thus writing a program in assembly language has advantages over writing the same in a
machine language.

High Level Language
High level language is the next development in the evolution of computer languages. Examples of
some high-level languages are given below
• PROLOG (for “PROgramming LOGic”)
• FORTRAN (for „FORrmula TRANslation‟)
• LISP (for “LISt Processing”)
• Pascal (named after the French scientist Blaise Pascal).
High-level languages are like English-like language, with less words also known as keywords and
fewer ambiguities. Each high level language will have its own syntax and keywords. The meaning of
the word syntax is grammar.

Translator Programs
Language Processors –
Compilers, interpreters, translate programs written in high-level languages into machine code that a
computer understands. And assemblers translate programs written in low-level or assembly language
into machine code. In the compilation process, there are several stages. To help programmers write
error-free code, tools are available.
Assembler
The Assembler is used to translate the program written in Assembly language into machine code.
The source program is an input of an assembler that contains assembly language instructions. The
output generated by the assembler is the object code or machine code understandable by the
computer. Assembler is basically the 1st interface that is able to communicate humans with the
machine. We need an Assembler to fill the gap between human and machine so that they can
communicate with each other. code written in assembly language is some sort of
mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on. and the assembler is
basically able to convert these mnemonics in Binary code. Here, these mnemonics also depend upon
the architecture of the machine.
For example, the architecture of intel 8085 and intel 8086 are different.

Interpreter
The translation of a single statement of the source program into machine code is done by a language
processor and executes immediately before moving on to the next line is called an interpreter. If there
is an error in the statement, the interpreter terminates its translating process at that statement and
displays an error message. The interpreter moves on to the next line for execution only after the
removal of the error. An Interpreter directly executes instructions written in a programming or
scripting language without previously converting them to an object code or machine code.
Example: Perl, Python and Matlab.
Compiler
The language processor that reads the complete source program written in high-level language as a
whole in one go and translates it into an equivalent program in machine language is called a
Compiler. Example: C, C++, C#, Java.
In a compiler, the source code is translated to object code successfully if it is free of errors. The
compiler specifies the errors at the end of the compilation with line numbers when there are any
errors in the source code. The errors must be removed before the compiler can successfully
recompile the source code again

Planning a Computer Program


It is the software developer who has to write down the solution to the problem in terms of simple
operations which the computer can understand and execute. In order to solve a problem by the
computer, one has to pass though certain stages or steps. They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.

Planning a Computer Program


1.Understanding the problem: Here we try to understand the problem to be solved in totally.
Before going to the next stage or step, we should be absolutely sure about the objectives of the given
problem.
2. Analyzing the problem: After understanding thoroughly the problem to be solved, we look
different ways of solving the problem and evaluate each solution. The idea here is to search an
appropriate solution to the problem under consideration. The end result of this stage is a broad
overview of the sequence of operations that are to be carries out to solve the given problem.
3. Developing the solution: Here the overview of the sequence of operations that was the result of
analysis stage is expanded to form a detailed step by step solution to the problem under
consideration. This is done with the help of algorithm, pseudo code and flowcharts.
4. Coding and implementation: The last stage of the problem solving is the conversion of the
detailed sequence of operations into a language that the computer can understand. Here each step is
converted to its equivalent instruction or instructions in the computer language that has been chosen
for the implantation.
Algorithm
Algorithm: The term algorithm refers to the logic of the program. It is a step by step description of
how to arrive at a solution to a given problem.
The characteristics of an Algorithm are as follow:
1. Each instruction should be precise and unambiguous.
2. No instruction should repeat infinitely.
3. It should give the correct result at the end.
Advantages of an algorithm
1. It is a step-by-step representation of a solution to a given problem ,which is very easy
to understand
2. It has got a definite procedure.
3. It is independent of programming language.
4. It is easy to debug as every step got its own logical sequence.
Disadvantages of an algorithm
1. It is time consuming process.
2. It is difficult to show branch and looping in the algorithm

Some Examples of algorithms:


Type 1 (Simple formula based)
Example 1 : Write an algorithm to print “Good Morning”.
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
Example 2 : Write an algorithm to find area of a rectangle.
Step 1: Start
Step 2: Take length and breadth and store them as L and B?
Step 3: Multiply by L and B and store it in area
Step 4: Print area
Step 5: Stop
Type 2 (based on conditional statements)
Example 3 : Write an algorithm to check whether he is eligible to vote? (More than or equal to
18 years old).
Step 1: Start
Step 2: Take age of the user and store it in age
Step 3: Check age value, if age >= 18 then go to step 4 else step 5
Step 4: Print “Eligible to vote” and go to step 6
Step 5: Print “Not eligible to vote”
Step 6: Stop
Example 4 : Write an algorithm to check whether given number is +ve, -ve or zero.
Step 1: Start
Step 2: Take any number and store it in n.
Step 3: Check n value, if n > 0 then go to step 5 else go to step 4
Step 4: Check n value, if n < 0 then go to step 6 else go to step 7
Step 5: Print “Given number is +ve” and go to step 8
Step 6: Print “Given number is -ve” and go to step 8
Step 7: Print “Given number is zero”
Step 8: Stop
Type 3 (Based on Looping statements)
Example 5: Write an algorithm to print all natural numbers up to n‟.
Step 1: Start
Step 2: Take any number and store it in n.
Step 3: Store 1 in I
Step 4: Check I value, if I<=n then go to step 5 else go to step 8
Step 5: Print I
Step 6: Increment I value by 1
Step 7: Go to step 4
Step 8: Stop In the above example, steps 4, 5, 6 and 7 are executed more than one time.
Flow chart
Flowchart is a program designing tool in which standard graphical symbols are used that illustrates
the sequence of operations to be performed to solve a given problem. In other words, it is a pictorial
representation of an algorithm or a process. It is also known as the Flow Diagram.
In a Flowchart the commands or statements of algorithm are shown as a special type of
shapes. Different types of shapes are used for different types of statements, and within those figures,
that statement is written briefly. These shapes are connected with each other with the help of arrows,
which show the flow of operation or processing.
A program‟s flow chart is like a roadmap for a programmer that guides him/her how to go
from a starting point to a final point while writing a program. While writing a flowchart, one is not
concerned with the details of a programming language so one can concentrate upon the logic of the
program.
The basic Symbol used in making flowcharts are as follows
1. Terminal :- The Oval is
used to show the beginning
and end of the Flowchart. It
is necessary that Flowchart
has a Start and Stop terminal. A flowchart should have only one Start and one Stop
terminal.
2.
2. Input/output :- Parallelogram shape is used to show the input and output operation in the
algorithm or program.

3. Processing:- Rectangular shape is used to show the processing section of an algorithm. In it, the
formulas and instructions are written, through which the data is being processed. When processing
has more than one instruction, then they are written in the same box. The instructions that are written
before, are executed first and which are written later, it is executed later
4. Decision :-The Rhombus/Diamond is used to show the decision section. It is used in the place
where we want to perform certain task only when a particular condition holds true or false. In this
case for each possible situation arising, different flow-lines are used to represent the flow of
execution.

5. Flow-lines :- The arrow shape is used to show the flow lines, these are used to
connect different shapes such as input output box, terminal, decision box, and
connector etc. It is also used to show the flow of the execution of the program. The
flow of execution of the program is determined by the direction of arrow mark on
the flow line.
6. Connectors :- The spherical / Circle shapes are used to represent the connectors. These are used
when the flowchart is so large that it cannot come to one page or the flow line of flowchart starts
cutting each other.
These shapes are , on which letters or numerals are written, so that they can know
their links in between. Similar letters or numbers written in a program, display the
continuous flow of the connector program.

Advantages / Benefits of Flowchart-


 Simple explanation of program :- Flowchart is a pictorial description of any program. The
program created by it can be easily understood.
 Effective analysis :- Through the flowcharts, the program is divided into smaller parts, that
making effective analysis of the program.
 Designing of program :- Using a flowchart, your program can be designed correctly and
easily .
 Easily debugging :- Flow chart is very helpful in detecting, locating and removing the
mistake in program.
 Documentation : A flow chart provide documentation support which is very helpful in
designing a good program.
Disadvantages / Limitations of Flowchart -
 Time consuming :- Creating a flow chart takes more time. The flow chart is made especially
for complex problems, which take more time.
 Difficult to make changes :- If there are some complex modification in the flow chart, then
the entire flowchart has to be recreated.
 No standard :- Program flowcharts, although easy to understand, but can not be written as a
standard, like others language. Each programmer resolves the problem in its own way and
creates a flow chart accordingly.
Some Example of Flowchart Program-
Example 1 : Create a flowchart to find the sum of two numbers

Example 2: Create a flow chart to find factorial on a number.


Example 3 : Create a flow chart to find the largest no. among 3 nos.

You might also like