Você está na página 1de 61

Introduction To Computer

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 is represented by the humans and the way it


is entered by a keyboard or displayed on a printer or
screen.
Internal Representation:- of information is the way it is

stored in the memory of a computer or passed to any


device of computer.

Information Representation
Externally, computers do use decimal digits, sign/magnitude

notations, and the familiar 26-character alphabets. However,


virtually every computer ever build stores data- numbers, letters,
graphics-internally using the binary numbering system.
Memor
y

0100000
1

Keyboar
d
External
Representation

A
Screen

Internal
Representation

Computer Uses Binary System


Why binary?
Electronic bi-stable environment
on/off,

high/low voltage
Bit: each bit can be either 0 or 1

Reliability
With

only 2 values, can be widely separated, therefore


clearly differentiated
drift causes less error

Example:

Binary Representation in Computer System

All information of diverse type is represented within

computers in the form of bit patterns.


e.g., text, numerical data, sound, and images here are two types of
information representation.

One important aspect of computer design is to decide

how information is converted ultimately to a bit pattern


Writing software also frequently requires understanding
how information is represented

Information Representation (Example)


Suppose a panel of experts is conducting

interview for selection of a job


Outside the meeting room there is a Bulb
If the bulb is on this means that a candidate
can move in for the interview otherwise he
has to wait.
So we have total two states
Bulb is ON
Bulb is OFF

If we represent this information in Binary how

many bits are required?

Information Representation (Example)


Now suppose we have four states
How many Bulbs are now needed to

represent this information???

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

represent this information???


2
One Red One Green

State

Green

Red

Go for Interview

OFF

OFF

No more Interviews today

OFF

ON

Wait for your turn

ON

OFF

Interviews will start after Tea Break

ON

ON

Information Representation
(Example)
Can we generalize?
Like Bulbs Binary digits have two states ON

(1) and OFF (0)


How many information's can be associated
with n bits?
2n
In order to represent n information's how
many bits are needed?
log2n

So for 4 bits of information we need ___ bits

Information Representation
Write all Bit Patterns that are possible with 3

Bits, 4 Bits and 5 Bits.

BCD (Binary Coded Decimal)


People are more accustomed to the

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

Grouping of Alphabetic, Numeric and other


characters that have some relationship in
common
For example the standard ASCII character
set includes letters, numbers, symbols and
control codes that make up the ASCII coding
scheme

American Standard Code for


Information Interchange(ASCII)

ASCII (American Standard Code for


Information Interchange)

A coding scheme that assigns Numeric


values to Letters, Numbers, Punctuation
marks and certain other characters

By standardizing the values used for these


characters, ASCII enables computers and
computer programs to exchange information

ASCII

ASCII provides for 256 codes divided into two


sets:

Basic Standard ASCII Set-----A 7 Bit Code


Extended ASCII Set ------- An 8 Bit Code

Standard ASCII

128 Character codes from 0 to 127 (00H to


7FH)

The first 32 Values are assigned


Communication and printer control codes

The remaining 96 codes are assigned to


common punctuation marks, the digits 0
through 9 and the uppercase and lowercase
letters of Alphabets.

to

Extended ASCII

The Extended ASCII set uses 8 bits for each


code yielding an additional 128 codes
numbered 128 through 255

Extended ASCII provides added capability by


allowing for 128 additional characters, such
as accented letters, Graphic Characters and
special symbols.

Extended ASCII codes

Extended Binary Coded Decimal


Interchange Code (EBCDIC)

A coding scheme developed by IBM for use with its


computers as a standard method of assigning
Binary (Numeric) values to Alphabetic, Numeric,
punctuation and Transmission Control Characters.
EBCDIC is analogous to the ASCII coding scheme.
It uses 8 bits for coding
ASCII is more or less universally acceptable in
Micro-computing Environment
EBCIDIC is not widely used with microcomputers
rather it is well known for the companys mainframe
and miniframe computers.

Unicode

Unicode uses two Bytes for each character


Instead of 256 character combination of ASCII-8,
Unicode handle 65,536 character combinations
This allows almost all written languages of the world
to be represented using a single character set

Powers of 2

2n comes up a lot in Computer Science.

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)

Some rough numbers:


210

kilo

220

mega

RAM

230

giga

disk

240

tera

BIG disk

250

peta

260

exa

knowledge

Logic Design

What is Processor Made Up


Of
Processor

Higher Level Structures


Adder, Multiplexer, register etc.

Logic Gates
AND, OR, NOT etc.

Transistors (Switch)

Transistors, Gates and Circuits


Transistors:- Transistor acts like a switch, which is
either in a ON state or OFF state.
Gates:A group of transistors are used to build
gate, which also acts like a switch (ON
or OFF). The
main difference b/w
transistor and gate is that,
first has
only one input, while second may has
many inputs.
Circuits:A group of Gates are used to build a
circuit, which is used to solve complex
problems (like microprocessor).

Transistor

voltage in
control high allows
current to flow -switch is closed (on)

control

voltage out

control low stops


current flow
switch is open (off)

Gates
Gate: a group of transistors (on =1, off = 0)
Gates are switches that distinguish between

two electrical voltages:


Current is low => 0
Current is high => 1
Basic Types:

AND Gate

OR Gate

NOT Gate

Gates and Boolean Algebra

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

Gates and Boolean Algebra (cont)

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
`

If both Input-1 and Input-2


are set to 1. This will put
both of the transistors into
the ON state, then the
resulting output will be 1.

Input-2

Output

OR Gate

OR Gate
Power
Supply

To construct OR gate, we
again must use two
transistors.

However, this time they


are connected in
parallel rather than in
series.

Input-1

Input-2

Output

If either, or both, of the


control lines Input-1
and Input-2 are set to
1, then the
corresponding
transistors will be in
the ON state.

NOT
Gate
A NOT gate requires
only a single transistor.

Resistor
Power
supply

Output
Input

Waste
basket

If the input line is a 1,


then the transistor will
pass the current
through, and it will be
discarded, producing an
output of 0.
If the input line is a 0,
the transistor blocks
passage of current to
the discard area, and it
is transmitted to the

Logic Gates, Truth Tables & Boolean Algebra

Distributive Property
(A + B) (A + C)

A Simple Logic Puzzle


Frank will go to the party if

Ed goes AND Dan does NOT.


Dan will go if Bob does NOT go OR if
Carole goes.
Ed will go to the party if Alice AND Bob
go.

Alice and Bob decide to go,


but Carol stays home.
Will Frank go to the party?
Answer: YES!

Using 0s and 1s
What do 0s and 1s mean?
For now, well take Natural

meanings:

0 = False

1 = True

For example, if we have a


variable Alice for whether Alice
goes to the party,
If Alice goes, we write Alice = 1
If Alice doesnt, we write Alice = 0

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

Zac will go to the party if Xena AND Yanni go


X

AND

Y
X Y

Truth Table

AND Gate (cont.)


W

AND

X
Y

AND

Shorthand:

W
X
Y

AND

AND Gate (cont.)

W
X
Y

AND

AND Gate (cont.)

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

c will go to the party if Xena OR Yanni go.


X

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

Logic Puzzle Circuit


Ed

AND
Dan

Frank

NOT

Frank will go to the party if


Ed goes AND Dan does NOT.

Logic Puzzle Circuit (cont.)


Ed

AND

Frank

Dan

Frank will go to the party if


Ed goes AND Dan does NOT.

Logic Puzzle Circuit (cont.)


Alice
Bob

AND

Ed

AND

Frank

Dan

Ed will go to the party if Alice AND Bob go

Logic Puzzle Circuit (cont.)


Alice
Bob

Carole

AND
OR

Ed

AND

Frank

Dan

Dan will go if Bob does NOT go


OR if Carole goes.

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

0
Carole

AND
OR

Ed

AND
Dan

Alice and Bob decide to go,


but Carol stays home.

Frank

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
1 AND
0

0
Carole

OR

Ed

AND
Dan

Evaluation

Frank

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
1 AND
0

0
Carole

OR

Ed

AND
Dan

Evaluation

Frank

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
1 AND
0

0
Carole

OR

Ed

0 Dan

Evaluation

AND

Frank

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
1 AND
0

0
Carole

OR

Ed

0 Dan

Evaluation

AND
1

Frank

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
1 AND
0

0
Carole

OR

Ed

0 Dan

AND

1 Frank

Evaluation Complete!
Answer: Frank goes to the party.

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

1
Carole

AND
OR

Ed

AND

Frank

Dan

What if:
Alice, Bob, and Carol all go to the party?

Logic Puzzle Circuit (cont.)


Alice 1
Bob 1

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

Você também pode gostar