Programming I
Muhammad Adnan Talib
Lec#3
15th Feb,2012
Computer Science Department
COMSATS Institute of Information Technology,
Sahiwal
Information Representation
There are two types of information representation.
External representation
Internal representation
External Representation:- the way in which
Information Representation
Externally, computers do use decimal digits, sign/magnitude
0100000
1
Keyboar
d
External
Representation
A
Screen
Internal
Representation
high/low voltage
Bit: each bit can be either 0 or 1
Reliability
With
Example:
State
Go for Interview
No more Interviews today
Wait for your turn
Interviews will start after Tea Break
Information Representation
(Example)
How many Bulbs are now needed to
State
Green
Red
Go for Interview
OFF
OFF
OFF
ON
ON
OFF
ON
ON
Information Representation
(Example)
Can we generalize?
Like Bulbs Binary digits have two states ON
Information Representation
Write all Bit Patterns that are possible with 3
decimal system
We store decimal numbers in the computer
in a way that they can be converted into
binary.
Example:
(185)10=(0001 1000 0101)BCD =(10111001)2 (Binary
Form)
Character Set
ASCII
Standard ASCII
to
Extended ASCII
Unicode
Powers of 2
Numbers to memorize:
21 = 2,
22 = 4,
23 = 8,
24 = 16,
25 = 32,
26 = 64,
27 = 128,
28 = 256,
29 = 512,
210 = 1024
Keep Memorizing
210 = 1,024
220 = 1,048,576
230 = 1,073,741,824
240 = 1,099,511,627,776
250 = 1,125,899,906,842,624
260 = 1,152,921,504,606,846,976
Powers of 2 (contd)
kilo
220
mega
RAM
230
giga
disk
240
tera
BIG disk
250
peta
260
exa
knowledge
Logic Design
Logic Gates
AND, OR, NOT etc.
Transistors (Switch)
Transistor
voltage in
control high allows
current to flow -switch is closed (on)
control
voltage out
Gates
Gate: a group of transistors (on =1, off = 0)
Gates are switches that distinguish between
AND Gate
OR Gate
NOT Gate
AND Gate
A AND B
0
0
1
1
0
1
0
1
0
0
0
1
OR Gate
A OR B
0
1
1
1
NOT Gate
NOT A
0
1
1
0
Power
supply
AND Gate
To construct and AND gate,
we must use of two
transistors connected in
series.
Input-1
`
Input-2
Output
OR Gate
OR Gate
Power
Supply
To construct OR gate, we
again must use two
transistors.
Input-1
Input-2
Output
NOT
Gate
A NOT gate requires
only a single transistor.
Resistor
Power
supply
Output
Input
Waste
basket
Distributive Property
(A + B) (A + C)
Using 0s and 1s
What do 0s and 1s mean?
For now, well take Natural
meanings:
0 = False
1 = True
AND Gate
Zac will go to the party if Xena AND Yanni
go.
X
t
u
Y
e Inp
l
b f
i
s o
X
s
s
o n
P
l tio
F
l
A na
F
bi
m
o
C
T
AND
Y
Truth Table
AND Gate
AND
Y
X Y
Truth Table
AND
X
Y
AND
Shorthand:
W
X
Y
AND
W
X
Y
AND
W
X
Y
AND
OR Gate
Zac will go to the party if Xena OR Yanni go.
X
t
u
e Inp
l
b f
i
X
s o
s
s
o
n
P io
F
l
l
t
A na
F
bi
m
o
T
C
OR
Truth Table
OR Gate
OR
Y
X Y
Truth Table
OR Gate (cont.)
W
OR
OR
Shorthand:
W
OR
X
Y
OR Gate (cont.)
W
X
Y
OR
OR Gate (cont.)
W
X
Y
OR
NOT Gate
Yanni will go to the party if Xena does
NOT go.
X
NOT
Shorthand:
X
X
Truth Table
AND
Dan
Frank
NOT
AND
Frank
Dan
AND
Ed
AND
Frank
Dan
Carole
AND
OR
Ed
AND
Frank
Dan
0
Carole
AND
OR
Ed
AND
Dan
Frank
1
1 AND
0
0
Carole
OR
Ed
AND
Dan
Evaluation
Frank
1
1 AND
0
0
Carole
OR
Ed
AND
Dan
Evaluation
Frank
1
1 AND
0
0
Carole
OR
Ed
0 Dan
Evaluation
AND
Frank
1
1 AND
0
0
Carole
OR
Ed
0 Dan
Evaluation
AND
1
Frank
1
1 AND
0
0
Carole
OR
Ed
0 Dan
AND
1 Frank
Evaluation Complete!
Answer: Frank goes to the party.
1
Carole
AND
OR
Ed
AND
Frank
Dan
What if:
Alice, Bob, and Carol all go to the party?
1
1 AND
0
1
Carole
OR
Ed
1 Dan
AND
0 Frank
What if:
Alice, Bob, and Carol all go to the party?
Answer: Frank does NOT go to the party!
THANK YOU