Anda di halaman 1dari 64

The Building Blocks: Binary Numbers, Boolean Logic, and Gates

Chapter 4

urpose o! Chapter
Learn ho" computers represent and store in!ormation# Learn "hy computers represent in!ormation that "ay# Learn "hat the basic building de$ices in a computer are, and ho" those de$ices are used to store in!ormation# Learn ho" to build more comple% de$ices using the basic de$ices#

'%ternal (epresentation o! )n!ormation


*hen "e communicate "ith each other, "e need to represent the in!ormation in an understandable notation, e#g#
*e use digits to represent numbers# *e use letters to represent te%t#

+ame applies "hen "e communicate "ith a computer:


*e enter te%t and numbers on the keyboard, The computers displays te%t, images, and numbers on the screen#

*e re!er to this as an e%ternal representation#


But ho" do humans,computers store the in!ormation -internally./
&

'%ternal (epresentation o! )n!ormation


0umans:
Te%t, numbers, images, sounds Te%t, numbers, sounds

Computers:
Te%t, numbers, images, sounds

+ynapses Neurons
Te%t, numbers, images, sounds

Binary Numbers
4

)n!ormation "e need to represent


Numbers
)ntegers 22&4, 4134 ositi$e,negati$e $alue 25166, 52&4 7loating point numbers 2 12#&41, &#141184

Te%t
Characters 2letters, digits, symbols4

9ther
Graphics, +ound, :ideo, ;

Numbering +ystems
*e use the decimal numbering system
16 digits: 6, 1, 2, &, 4, 1, 3, <, =, 8 7or e%ample: 12

*hy use 16 digits 2symbols4/


(oman: ) 2>14 : 2>14 ? 2>164 L 2>164, C2>1664 ?)) > 12, entium ):

*hat i! "e only had one symbol/


))))) ))))) )) > 12
3

The Binary Numbering +ystem


@ll computers use the binary numbering system
9nly t"o digits: 6, 1 7or e%ample: 16, 16661, 16116

+imilar to decimal, e%cept uses a di!!erent base


Binary 2base524: Aecimal 2base5164: 9ctal 2base5=4: 0e%adecimal 2base5134: 6, 1 6, 1, 2, &, 4, 1, 6, 1, 2, &, 4, 1, 6, 1, 2, &, 4, 1, @, B, C, A, ', 7 3, <, =, 8 3, < 3, <, =, 8, 2@>16, ###, 7>114

*hat do "e mean by a base/

<

Aecimal $s# Binary Numbers


*hat does the decimal $alue 13& stand !or/
13& 162 1 161 3 166 & %1

base

%166

B %16

*hat does the binary $alue 161 stand


!or/
161 22 1 %4 B 21 6 %2 B 26 1 %1

base

Binary5to5Aecimal Con$ersion Table


Aecimal 6 1 2 & 4 1 3 < Binary 6 1 16 11 166 161 116 111 Aecimal = 8 16 11 12 1& 14 11 Binary 1666 1661 1616 1611 1166 1161 1116 1111 Aecimal 13 1< 1= 18 26 21 22 2& Binary 16666 16661 16616 16611 16166 16161 16116 16111 Aecimal 24 21 23 2< 2= 28 &6 &1 Binary 11666 11661 11616 11611 11166 11161 11116 11111

Con$erting !rom Binary to Aecimal


*hat is the decimal $alue o! the binary $alue 161 / 22 21 26 161 1 %4 4 B B 6 %2 B 6 B 1 %1 1

>1
26 6 B %1 B 6

*hat is the decimal 1116 / 2& 1116 1 %= B = B

$alue o! the binary $alue 22 1 %4 B 4 B 21 1 %2 2

> 14
16

Bits
The t"o binary digits 6 and 1 are !reCuently re!erred to as bits# 0o" many bits does a computer use to store an integer/
)ntel entium C > &2 bits

*hat i! "e try to compute a larger integer/


)! "e try to compute a $alue larger than the computer can store, "e get an arithmetic o$er!lo" error#
11

(epresenting Dnsigned )ntegers


0o" does a 135bit computer represent the $alue 14/
6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 6

*hat is the largest 135bit integer/


1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

> 1%211 B 1%214 B ### B 1%21 B 1%26 > 31,1&1


12

(epresenting +igned )ntegers


0o" does the computer represent signed $alues/
Three schemes ha$e been used: +igned magnitude 1Es complement 2Es complement *hile unsigned binary is in some sense -natural. signed binary arithmetic is a human construct There is a best "ay 5 "hich is "hat "e all use today

1&

(epresenting +igned )ntegers


+igned Fagnitude 7irst bit is the sign bit: 6>G B$e 1>G 5$e (emainder is the magnitude 2i#e# numeric $alue4

6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 6

+ign bit#
B14 in signed magnitude representation

1 6 6 6 6 6 6 6 6 6 6 6 1 1 1 6
514 in signed magnitude representation

roblems @rithmetic logic is comple% There are t"o Heros: 6666666666666666 1666666666666666
14

(epresenting +igned )ntegers


1Es Complement There is no sign bit but an algorithm: To con$ert !rom B$e to 5$e and $ice $ersa: in$ert 2E!lipE4 all the bits

6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 6
B14 in 1Es complement representation

1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 1
514 in 1Es complement representation

roblems @lthough arithmetic is much simpler, there are t"o Heros: 6666666666666666 1111111111111111
11

(epresenting +igned )ntegers


2Es Complement There is no sign bit but an algorithm: To con$ert !rom B$e to 5$e and $ice $ersa: in$ert 2E!lipE4 all the bits then add 1

6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 6
B14 in 2Es complement representation

1 1 1 1 1 1 1 1 1 1 1 1 6 6 1 6
514 in 2Es complement representation

+imple arithmetic 2like 1Es complement4 9nly one Hero:


6666666666666666 1111111111111111 B1 6666666666666666 -B6., con$ert:

13

(epresenting 7loating oint Numbers


0o" do "e represent !loating point numbers like 1#<1 and 514&#16/ Three step process:
Con$ert the decimal number to a binary number# *rite binary number in -normaliHed. scienti!ic notation# +tore the normaliHed binary number#

Look at an e%ample:
0o" do "e store the number 1#<1/
1<

1# Con$ert decimal to binary

2& =

22 4

21 2

26 1

251

252

4B
6 1 6

1BJB I > 1#<1


1 1 1

1#<1 decimal >161#11 binary


1=

2# Dsing normaliHed scienti!ic notation


+cienti!ic notation : K F % B K'
B is the base, F is the mantissa , ' is the e%ponent# '%ample: 2decimal, base>164
& > & % 166 2616 > 2#61 % 16& 2e#g# & L 14 2e#g# 2#61 L 16664

'asy to con$ert to scienti!ic notation:


161#11 % 26

NormaliHe to get the -#. in !ront o! !irst 2le!tmost4 1 digit


)ncrease e%ponent by one !or each location -#. mo$es le!t 2decreases i! "e ha$e to mo$e right4 161#11 % 26 > #16111 % 2&

18

&# +tore the normaliHed number


Base 2 implied, not stored

B #16111 % 2B&

6 1 6 1 1 1 6 6 6 6 6 6 6 6 1 1

Fantissa 216 bits4


@ssumed binary point

'%ponent 23 bits4

26

(epresenting Te%t
0o" can "e represent te%t in a binary !orm/
@ssign to each character a positi$e integer $alue 2!or e%ample, @ is 31, B is 33, ;4 Then "e can store the numbers in their binary !ormM

The mapping o! te%t to numbers


Code mapping

Need standard code mappings 2"hy/4:


@+C)) 2@merican +tandard Code !or )n!ormation )nterchange4 >G each letter =5bits only 213 di!!erent characters can be represented 22=4 Dnicode >G each letter 135bits 2sometimes4
21

@+C)) Code mapping Table


Char )nteger
&2 M ; 6 1 2 ; && &4 ; 4= 48 16 ;

Binary
66166666 66166661 66166616 ; 66116666 66116661 66116616 ;

Char )nteger
@ B C ; % y H ; 31 33 3< ; 126 121 122 ;

Binary
61666661 61666616 61666611 ; 61111666 61111661 61111616 ;

22

'%ample o! (epresenting Te%t


(epresenting the "ord -0ello. in @+C))
Look the $alue !or each character up in the table 2Con$ert decimal $alue to binary4
0 <2 61661666 e 161 61166161 l 16= 61161166 l 16= 61161166 o 111 61161111

2&

e%ample
C+c 61666611 61616611 61166611 112
C + c

66116661 66116661 66116616


1 1 2

Notice the di!!erence bet"een @+C)) E112E and binary representation o! 11216: 6111 6666
24

0e%adecimal
Decimal 6 1 2 & 4 1 3 < Binary 6666 6661 6616 6611 6166 6161 6116 6111 6 1 2 & 4 1 3 < Hex Decimal = 8 16 11 12 1& 14 11 Binary 1666 1661 1616 1611 1166 1161 1116 1111 = 8 @ B C A ' 7 Hex

e%: 112 > 6111 6666 > <613 123 > 6111 1116 > <'13
21

*hy use Binary Numbers/


*hy not use the decimal systems, like humans/ The main reason !or using binary numbers is:
(eliability

*hy is that/
'lectrical de$ices "ork best in a bistable en$ironment, that is, there are only t"o separate states 2e#g# on,o!!4# *hen using binary numbers, the computers only need to represent t"o digits: 6 and 1
23

Binary +torage Ae$ices


*e could, in theory at least, build a computer !rom any de$ice:
That has t"o stable states 2one "ould represent the digit 6, the other the digit 14 *here the t"o states are -di!!erent. enough, such that one doesnNt accidentally become the other# )t is possible to sense in "hich state the de$ice is in# That can s"itch bet"een the t"o states#

*e call such de$ices binary storage de$ices


Can you think o! any/

2<

Transistor
The binary storage de$ice computers use is called a transistor:
Can be in a stable 9n,9!! state 2current !lo"ing through or not4 Can sense in "hich state it is in 2measure electrical !lo"4 Can s"itch bet"een states 2takes O 16 billionths o! a secondM4 @re e%tremely small 2can !it G 16 million,cm2 , shrinking as "e speak4

Transistors are build !rom materials called semi5 conductors


e#g# silicon

The transistor is the elementary building block o! computers, much in the same "ay as cells are the elementary building blocks o! the human bodyM
2=

Transistor P Conceptual Fodel


)n 2Collector4 Control 2Base4

9ut 2'mitter4
The control line 2base4 is used to open,close s"itch:
)! $oltage applied then s"itch closes, other"ise is open

+"itch decides state o! transistor:


9pen: no current !lo"ing through 26 state4 Closed: current !lo"ing through 21 state4
28

7uture Ae$elopment/
Transistors
Technology impro$ing, allo"ing us to pack the transistors more and more densely 2:L+), DL+), ;4

Can "e in$ent more e!!icient binary storage de$ices/


ast: resent: 7uture: Fagnetic Cores, :acuum Tubes Transistors /

Quantum Computing/
&6

Boolean Logic and Gates

&1

Boolean Logic
Boolean logic is a branch o! mathematics that deals "ith rules !or manipulating the t"o logical truth $alues true and !alse# Named a!ter George Boole 21=1151=344
@n 'nglish mathematician, "ho "as !irst to de$elop and describe a !ormal system to "ork "ith truth $alues#

*hy is Boolean logic so rele$ant to computers/


Airect mapping to binary digitsM 1 > true, 6 > !alse

&2

Boolean '%pressions
@ Boolean e%pression is any e%pression that e$aluates to either true or !alse# )s 1+3 a Boolean e%pression/
No, doesnNt e$aluate to either true or !alse#

'%amples o! Boolean e%pressions:


? G 166 ?OR @ > 166 2G&

&&

Boolean 9perators
*e use the three !ollo"ing operators to construct more comple% Boolean e%pressions
@NA 9( N9T

'%amples:
? G 166 @NA ?O216 @>>6 9( BG166

&4

Truth Table !or @NA


Let a and b be any Boolean e%pressions, then

a 7alse 7alse True True

b 7alse True 7alse True

a @NA b 7alse 7alse 7alse True

'%amples
?G6 @NA ?O26 ?>16 @NA ?GR

? is 16 and R is 11 True 7alse


&1

Truth Table !or 9(


Let a and b be any Boolean e%pressions, then a 7alse 7alse True True b 7alse True 7alse True a 9( b 7alse True True True

'%amples
?G6 9( ?O26 ?>16 9( ?GR

? is 16 and R is 11 True True


&3

Truth Table !or N9T


Let a be any Boolean e%pression, then
a 7alse True N9T a True 7alse ? is 16 and R is 11 7alse True
&<

'%amples
N9T ?G6 N9T ?GR

Boolean 9perators 2cont#4


@ssume ? is 16 and R is 11# *hat is the $alue o! the Boolean e%pression/
?>16 9( ?>1 @NA RO6 2?>16 9( ?>14 @NA RO6 ?>16 9( 2?>1 @NA RO64 7alse True

*e should use parentheses to pre$ent con!usionM


&=

'%amples o! Boolean '%pressions


@ssuming ?>16, R>11, and S>26# *hat do the !ollo"ing Boolean e%pressions e$aluate to/
22?>>164 9( 2R>>1644 @NA 2SG?4 2?>>R4 9( 2N9T 2?GS44 N9T 2 2?GR4 @NA 2SGR4 @NA 2?OS4 4 2 2?>>R4 @NA 2?>>164 4 9( 2ROS4
true true true true

&8

Gates
@ gate is an electronic de$ice that operates on a collection o! binary inputs to produce a binary output# *e "ill look at three di!!erent kind o! gates, that implement the Boolean operators:
@NA 9( N9T

46

@lternati$e Notation
*hen "e are re!erring to gates, "e use a di!!erent notation !rom Boolean e%pressions:
a @NA b a 9( B N9T a aTb aBb Wa a UU b a VV b a ab ab Ma

The !unctionality o! the operators is the same, Xust a di!!erent notation#

41

Gates
Types o! gates
@NA 9( N9T ?9( N@NA N9(
42

Gates $s# Transistors


*e can build the @NA, 9(, and N9T gates !rom transistors# No" "e can think o! gates, instead o! transistors, as the basic building blocks:
0igher le$el o! abstraction, donNt ha$e to "orry about as many details# Can use Boolean logic to help us build more comple% circuits# 2But not in this course4

4&

+ummary so !ar
(epresenting in!ormation
'%ternal $s# )nternal representation

Computers represent in!ormation internally as


Binary numbers

*e sa" ho" to represent as binary data:


Numbers 2integers, negati$e numbers, !loating point4 Te%t 2code mappings as @+C)) and Dnicode4 2Graphics, sound, ;4

44

+ummary so !ar 2cont#4


*hy do computers use binary data/ (eliability 'lectronic de$ices "ork best in a bistable en$ironment, that is, "here there are only 2 states# Can build a computer using a binary storage de$ice:
0as t"o di!!erent stable states, able to sense in "hich state de$ice is in, and easily s"itch bet"een states#

7undamental binary storage de$ice in computers:


Transistor

41

+ummary so !ar 2cont#4


Boolean Logic
Boolean e%pressions are e%pressions that e$aluate to either true or !alse# Can use the operators @NA, 9(, and N9T

Learned about gates


'lectronic de$ices that "ork "ith binary input,output#

Ne%t "e "ill talk about:


Circuits built !rom gates#

43

Computer Circuits

4<

urpose
*e ha$e looked at so !ar ho" to build logic gates !rom transistors# Ne%t "e "ill look at ho" to build circuits !rom logic gates, !or e%ample:
@ circuit to check i! t"o numbers are eCual# @ circuit to add t"o numbers#

Gates "ill become our ne" building blocks:


0uman body: cells5Gorgans5Gbody Computers: gates5Gcircuits5Gcomputer

4=

Circuit
@ circuit is a collection o! interconnected logic gates:
that trans!orms a set o! binary inputs into a set o! binary outputs, and "here the $alues o! the outputs depend only on the current $alues o! the inputs

These kind o! circuits are more accurately called combinatorial circuits#

48

Circuit 2e%ternal $ie"4


@ circuit can ha$e any number o! inputs and outputs:
Number o! inputs and outputs can di!!er# The inputs and outputs are either 6 or 1#

16

Circuit 2e%ternal $ie" cont#4


9utput depends only on current input $alues
'ach set o! input al"ays generates the same output# Ai!!erent sets o! input can generate identical output#

1 0

1 0

C)(CD)T
1 0 0 1

)N DT

9DT DT
11

Circuit 2internal $ie"4


Circuits are build !rom interconnected @NA, 9( and N9T gates, in a "ay such that each input combination produces the desired output#

12

'%ample
*hat are the output $alues c and d gi$en input $alues a>1, b>6/
1

1&

Circuit Aiagrams and Boolean '%pr

The diagrams "e "ere looking at are called circuit diagrams# (elationship bet"een circuit diagrams and Boolean e%pressions:
'$ery Boolean e%pression can be represented pictorially as a circuit# '$ery output in a circuit diagram can be "ritten as a Boolean e%pression#

'%ample 2output $alues c and d !rom pre$ious diagram4:


c > 2 a 9( b4 d > N9T 2 2a 9( b4 @NA 2N9T b4 4

14

Circuits Aiagram and Boolean '%pr


Aeri$ing Boolean e%pressions !or the output#
a
(a OR b) (a OR b) (a OR b) AND (NOT b) NOT ((a OR b) AND (NOT b))

(NOT b)

11

Circuits Aiagram and Boolean '%pr


(emember, "hen "riting Boolean e%pressions !or circuit diagrams, "e can use a di!!erent notationM
a (a + b) (a + b) b b b
13

(a + b)

(a + b) b

'%ample
*hat Boolean e%pression describes the output/

a b

ab ab + ab a b ab

1<

Control Circuits
+o !ar "e ha$e seen t"o types o! circuits:
Logical 2 is a > b /4 @rithmetic 2 c > a B b4

Computers use many di!!erent logical 2G, O, G># O>, M>, ;4, and arithmetic 2B,5,L,,4 circuits# There are also di!!erent kind o! circuits that are essential !or computers control circuits
*e "ill look at t"o di!!erent kind o! control circuits, multiple%ors and decoders#

1=

Fultiple%or
@ multiple%or circuit has:
2N 1 N input lines 2numbered 6, ;, 2N514 output line selector lines

The selector lines are used to choose "hich o! the input signals becomes the output signal:
+elector lines are interpreted as an N5bit integer The signal on the input line "ith the corresponding number becomes the output signal#

18

Fultiple%or 2cont#4
6 1 6 1 6 1 2 & Fultiple%or 1 6

6 1

1 6

36

Aecoder
@ decoder circuit has:
N 2N input lines 2numbered 6, 1, ;#, N514 output line 2numbered 6, 1, ; 2N514

*orks as !ollo"s:
The N input lines are interpreted as a N5bit integer $alue# The output line corresponding to the integer $alue is set to 1, all other to 6

31

Aecoder 2cont#4
6 6 6 6 1 6 6 6

6 6 1

0 1 2

0 1 2 3 4 ! 7

Aecoder

100 " 4

32

+ummary
*e looked at ho" computers represent data:
)nternal $s '%ternal (epresentation Basic storage unit is a binary digit - bit Aata is represented internally as binary data# Dse the binary number system#

*e learned "hy computers use binary data:


Fain reason is reliability 'lectronic de$ices "ork best in bi5stable en$ironment#

3&

+ummary 2cont#4
*e looked at the basic building blocks used in computers:
Binary +torage Ae$ice > Transistor

*e sa" ho" to build logic gates 2@NA, 9(, N9T4:


Transistors Gates Boolean logic

34

Anda mungkin juga menyukai