Transcript 2 - CFD

foc
Introduction
1
Evolution of computers
First: abacus,
a help to calculation
BC 500 :Babylon
1642 B Pascal improves it. See d time gap!
laise
1823 C Babbage A
harles
da
Byron
, Analytical Engine
It stored 1000 twenty digit decimal
numbers and a modifiable program so
that , it could do different computing jobs
2
Evolution of computers
It had 50,000 mechanical parts, and still
it could not give reliable results. Lacked
precision!
More the parts, more the trouble!
Too many cooks spoil the broth!
Too many leaders, spoil the people
3
Evolution of computers
With the advent of electrical motors and
machines, Hollerith, in 1889, made a
machine to count, calculate and sort; still
using punched cards
First electronic calculating computer was
developed by Konrad Zuse in 1941 and
was called Z3. But Turing is credited for
the first electronic computer in 1943,
called Colossus. But it was not
programmable.
4
Evolution of computers
The first general purpose computer was
developed in 1946, was called ENIAC:
Electronic Numerical Integrator and
Calculator. It had 17000 vacuum tubes, over
500 miles of wire and weighed 30 tons! It
could do 100,000 operations per second.
Necessity is the mother of inventions! ?
5
Evolution of computers
In 1950 UNIVAC I, UNIVAC II, UNIVAC 1103
1948:Transistor
1958: general purpose computers using
transistors: efficient, small and faster.
1958: Integrated Circuits.
1960: computers using s &m s IC
1971: single chip microprocessor (4004)
1972:8 bit microprocessor (8008)
1973:Improved 8 bit microprocessor
(8080) and MC6800
mall
edium
cale
6
Evolution of computers
1974:The 8 bit processor was 8085.
1978:8086!
1979: 8088 family of microprocessors
final
1981: IBM used 8088 in PC personal computer
1983: Improved version of 8086 known
as 80286, A 16 bit micro processor!
7
Evolution of computers
1986:32 bit micro processor 80386 !
1989: the 80486
1993:Pentium in
Desktops give way to lap tops, palm tops
and even to cell phones these days!
8
Languages for the computers
1950: Assembly language for UNIVAC
1957: FORTRAN. Formula translation
.
Then came ALGOL, COBOL, BASIC,
PASCAL, C/C++, ADA and JAVA
Then came OS: MS DOS, MS WINDOWS,
UNIX, LINUX
O S:to supervise & manage comp. Recourses.
Using :Easy for users
Utilization:- Efficient .
9
Generation of Computers
10
Classification of computers based on size
Super computer
Mainframe computer
Mini computer
Workstations
Micro computer
personal
Laptop/notebook
Palm top
11
Classification
of computers
based on purpose.
General purpose
Special purpose
12
Classification
of computers
based on technology
analog
digital
Hybrid
13
Organization of a computer
The basic units :
CPU,
memory unit,
input unit
output unit
Input devices
CPU: calculate, compare, copy…
Memory module: primary and secondary
14
15
Organization of a computer
Memory operations: read, write
Units of memory: byte, KB, MB, GB, TB,
Personal computer: H/W and S/W
16
Organization of a computer
Input devices, output devices, modem, PM,
PM types RAM, ROM, PROM, …
Internal processor memory, secondary
mem, CD rom,
Memory hierarchy
17
18
Software/ operating systems
Loading of OS to a PC
Booting, Basic I/O system
Operational overview of a computer
19
NUMBER SYSTEMS
There are many systems. They used sticks for
numbers. V for 5 sticks, and X for 10 sticks.
About 1500 years back indians used 0 as
a number which was taken to Arabs (sifr)
and then to the west (Zephiro),(Zero).
Every number system has a base.
20
NUMBER SYSTEMS
Our common decimal system has a base
10. so 257 is to be understood as
7 singles + 5 tens + 2 hundreds! = 257
7 * 100 + 5 * 101 + 2 * 102 = 257
1 + 7 * 100
2
5
*
10
2 * 10 +
21
NUMBER SYSTEMS
Clearly the position at which a digit is
written, is significant. If the above
number is written as 752, the entire
meaning changes.
7* base0 + 5 * base1 + 2 * base2 = 257
The weighting factor for 7 in 257 is 100 ie 1
and for 5 is 101 ie 10 and for 2 is 102 ie 100
22
Different number systems are
Binary
Ternary
Quaternary
Quinary
Octal
Decimal
Duodecimal
Hexadecimal
Vigesimal
23
Binary number system
Here we have only two different digits namely 0
and 1. now let us find the actual value of 1100
1 1 0 0
0*20
0*21
1*22
1*23
=0 +
= 0 +
= 4 +
= 8
12
weight
Multiplier
Multipliers
are written
and weights
are assumed
from pos
24
Binary number system
Find out the value of 23618 in decimal
What will be the decimal equivalent of
34928 ?!
25
Hexa decimal system
Digits are from 0 to 15 ! Then
how do you represent 10, 11….
10
11
12
13
14
15
A
B
C
D
E
F
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
A
B
C
D
E
F
26
Decimal to Binary conversion
convert
decimal 19 to binary
19
2
9
2
1
4
2
1
2
2
2
0
1
0
0
1
Divide the number by 2.
note the remainder
Continue the same process on
the quotient, till it becomes 0
Write the remainders from
the last to first order as
shown by the arrow
Thus 1910 is 100112
27
Conversion from binary to decimal.
Convert 110102 to x10
1 1 0 1 0
.
0 * 2 01
1*22
0*23
1*2
1*24
=0 +
=2 +
= 0 +
= 8 +
= 16
26
Multi weight
plier
28
Decimal to Octal conversion: convert decimal 8410 to x8
Here we continuously divide by 8 getting the quotient
and the remainder. Go on till the quotient becomes 0.
write the remainders in the reverse order
We check how many 8s are there
in 84. the rest should be singles!
8 84
We see there are 10 8s making it 80.
8 10 4
0s) are there. then in
rest
4
singles(8
1
2
8
this 80 we check how many 82 or
0
1
64s are there. The rest should be 8s.
Thus the octal
equivalent of
We see 1 64 and 2 81s are there in 80
decimal 84 is 124.
Finally in 1 we see 0 83s are there
Thus 8410 is 1248
and rest 1 82 is there
29
Hexadecimal to decimal conversion: convert
Hexadecimal 2B416 to x10
2 B 4
.
4 * 160 =
11 * 161 =
2 * 162 =
4 +
176 +
512
692
Multiplier weight
Thus 2B416 is 69210
30
Convert 894510 to x16
16 8945
16 559 1
16 34 15 F
16 2
0
1
2
Thus the Hexadecimal equivalent of decimal 8945 is
21F1
Thus 894510 is 21F116
31
Non decimal to Non decimal conversion:
In order to convert a number from any system S1
other than decimal to another system S2 other than
decimal, we first convert S1 to decimal and then
convert that decimal number to S2.
Thus X16 to Z8 can be done by X16  Y10 and then Y10  Z8
But if the base of X is a power of Z then the conversion
can be done directly as A5 == 1010 1001 in binary and
Convert each digit directly into other system nibble by
nibble because hexadecimal base is 15 and binary is 2
and 16 = 24. So 4 bits at a time! F8B == 1111 1000 1100
.
32
F8B == 1111 1000 1100
1101101101 is 0011 0110 1101 === 36D
73258 111 011 010 101
.
10 011 1002 is 2348
Group the binary digits into groups of 3 from the right
and convert each one to octal
33
Conversion of fractions
Convert 0.49 to binary
0.49 * 2 = 0.88  0
0.88 * 2 = 1.76  1
0.76 * 2 = 1.52  1
0.52 * 2 = 1. 04  1
0.04 * 2 = 0. 08  0
0.08 * 2 = 0. 16  0
Thus 0.49 10  0.001110
For more precision we can go further
34
Conversion from binary fraction to decimal
Convert 0. 1 0 1 1 to decimal
0. 1 0 1 1
1 * 2-1 =
0 * 2-2 =
1 * 2-3 =
+1 * 2-3 =
0.5 +
0.0 +
0.125
0.0625 +
0.6875
Thus 0.10112 = 0.687510
35
Conversion of octal fraction to decimal
Convert 237.048 to x10
2 3 7 .0 4
4 * 8-2 =
0 * 8-1 =
7 * 80 =
3 * 81 =
2 * 82 =
0 .0625
0
7
24
128
159 . 0625
+
+
+
+
36
Conversion from binary fraction to octal
Convert 010.110 to octal
0 1 0 . 1 1 0
.
6
2
Convert 01010.110101 to octal
0 1 0 1 0 . 1 1 0 1 0 1
1
2
.
6
5
37
Conversion from binary fraction to Hexadecimal
Convert 0110.1101 to Hexadecimal
0 1 1 0 . 1 1 0 1
6
.
13 (D)
Convert 1001010.110101 to Hexadecimal
1 0 0 1 0 1 0 . 1 1 0 1 0 1
4
10 (A)
.
13(D)
1
38
ALGORITHMS/ step forms
What is algorithm?
It is a plan for a computer program.
An effective procedure for solving a problem in finite steps
Algorithm to make Tea
1. If the kettle is not filled with water, fill it with water
2.Plug the kettle to power and switch on
3.If the tea pot is not empty, then empty the tea pot
4.Place the tea leaves in the tea pot
5.If the water in the kettle is not boiling, go to step 5
6.Switch off the kettle
7.Pour the water from the kettle to teapot
.
.
39
Features of algorithm
Sequence (process) relates to the order. We can not have any order for an algorithm
Decision (selection) based on a condition some action is selected
Repetition (looping or iteration) some action/s are repeated finite number of times
Decision can be of two forms
1. If condition
Then action
2. If condition
Then action1
Else
action2
The repetition constructs
Repeat …………… Until
Repeat
action 1
.
action 2
Until condition satisfied
40
While (proposition) begin ………… end
While(kettle is not full)
Begin
pour water into the kettle
end
While (proposition)
Begin
.
action 1
action 2
.
………
action n
end
The same by using if then goto
1.
2.
1.
2.
.
3.
4.
.
5.
Pour water into the kettle
If the kettle is not full, then goto step 1
Action 1
Action 2
Action 3
……
If(proposition) then goto step 1
41
Variable is one whose value can vary.
Let us write an algorithm to boil some water
1. Pour water into a kettle
2. Connect a thermometer to take temperature readings
3. Connect the plug to power and switch it on
4. If the temperature is not equal to 1000C go to step 4
Here temperature is a variable and till it reaches 100, the process continues
Variabls are of different types like
numeric (integer, float, double..)
alphabetic ‘a’, ‘b’, or “University”
logical (ie true or false type)
Variable name should be meaningful.
Variable names shall be meaningful nouns.
.
.
.
42
Other ways of planing for a program are
Psuedo code
Flow chart
Nassi_Schneiderman
.
.
.
.
.
.
.
.
.
.
43
Other ways of planning for a program are
Psuedo code
A human understandable, easy to use way of expressing a programe flow
It uses, a well defined, restricted vocabulary.
Do while kettle not full
Add water to kettle
End dowhile
.
.
44
Flow chart
It provides the steps to be followd to arrive at a solution to a problem. So it is a
program design tool
Flow charts comprises of a set of figures of various shapes that are connected by
flow lines. Flow lines have arrows showing the direction of flow of control
.between the figures. The action to be taken is written in the figures. Flow charts
can
. have connectors. Flow charts help understanding and explaining the problem
to the others
Standards for flow charts
They shoiuld start at the top and flow down and to the right
Only standard symbols should be used
Commonly understandable language should be used (not programming lang)
Flow chart for each subroutine should be drawn in separate pages with proper
starting and terminal symbols!
Arrows should be used to indicate the flow direction
45
.Flow Chart
Abcd
Pqua
xysz
Only one flow line should emerge from a process symbol
Only one flow line should enter a decision symbol, whereas multiple lines can
emerge from a decision symbol
Only one flow line should emerge from a start and no flow line shall emerge from
an end/stop
Arrows should be used to indicate the flow direction
46
.Flow Chart symbols from net
Also
examples from the net
.
.
.
47
Program cycle
Define the problem
Design the solution
Code the program
Test the program
Document the program
Implement the program
Maintain the program
Commonly understandable language should be used (not programming lang)
Flow chart for each subroutine should be drawn in separate pages with proper
starting and terminal symbols!
Arrows should be used to indicate the flow direction
48
compiler
It checks for erros and lists them out
If no error, compiler generates the machine code for the program (object code)
which can be executed
errors
Object code
compiler
Object code in
Machine language
Syntax refers to the arrangement of words in a statement or the format/appearance or
general shape of a statement ( I ate a mango) noun, verb, noun
Semantics refers to the meaning/sense behind. (Mango ate i) noun verb noun
but no sense
49
Hexadecimal to decimal conversion convert Hexadecimal 28416 to x10
Convert 8410 to x8
Here we continuously divide by 8 getting the quotient and the remainder. Go on
till the quotient becomes 0. write the remainders in the reverse order
8
84
8
8
10
4
1
2
0
1
Thus the octal equivalent of decimal 84 is 124.
Thus 8410 is 1248
50