Chapter 1
Digital Systems and Binary Numbers
1.1 DIGITAL SYSTEMS
Digitalsystems havesuch aprominent rolein everydaylifethatwerefertothepresenttech- nolo gicalperiodasthedigital(IKe.DigitalS)' SICm Sareusedincommunication. businesstrans- actions.trafficcontrol."paceguidance.medicaltreatment.weather mon itoring,theInternet,and many othercommercial.industrial. andscientificenterprises.Wehavedigitaltel ephones.dig- iraltelevision.digital versatilediscs.digitalcameras.handhelddevices.and.of course.digi- talcomputers.Themost strikingpropertyofthe digitalcomputerisilsgenerality.Itcanfollow asequence ofinstructions. calledaprogram.thatoperateson givendata.Theusercanspecify andchangetheprogramorthe dataaccordingtothespecifi c need.Because ofthisflexibifiry, general- purposedigitalcomputers canperformavariety ofInformation-processingtasksthat ranBe overa widespectrum orapplications.
Onecharacteristicofdigitalsystems istheirabilityto representandmanip ulatediscreteel- ementsofinformation.Anyset thatisrestricted Ina finitenumberof clementscontainsdis- creteinformation.Examplesofdiscrete sets are the10decimal digits.the26lettersofthe alphabe t the52playing cards.andthe6-tsquaresofachessboard .Earlydigitalcom puters wereused for numericcomputations.Inthis cas e.thediscrete elementswerethedigits.From thisapplication.thetermdigita!com puteremerged.Discreteclement s ofinformationarerep- resented inadigitalsystembyphysicalquantitiescalledsignals.Elect ricalsignalssuchas voltagesandcurrentsarcthemost common.Electronicdevicescalledtransistorspredominate in the circuitrythatimplementsthesesignals.The signa ls in mostpresent-dayelectro nic dig- italsystems use justtwo discretevalues andarethereforesaid to bebiliary.A binarydigit.
calledabit.hastwovalues:0and I.Discreteclements of infonnationarerepresent edwith
groups
ofbits
calledbinary codes. F or
example.the decima l digits0throu gh9 are represemedin ' disit, l ' r'temw ith a code of fo u r bits (e.g .. the number 7 is represented b y01 1 1 ).
2 Chapter 1 Digital Systems and Binary Numbers
Throu gh various techniques, groups of bits can be made to represent discrete symbols, which are then used to develop the system in a digita l fermat. Thus, a digital sys tem is a system that manipulates discrete clements of information represented internally in binary fonn .
Discrete quantities of information either emerge from the nature of the data being processed or may bequ antiz ed from a co ntinuous process. On the one hand, a payroll schedule is an in- herently disc rete process that contains employee names, socia l sec urity numbers, weekly salaries, income taxes, and so on. An employee's paycheck is processe d by means of discrete data values such as letters of the alphabet (names), digits (salary), and special symbols (such as $). O n the other hand . a research scientist may observe a continuous process, but record only specific quantities in tabular fonn . The scientist is thus quantizing continuous data. mak- ing each number in his or her table a discrete quantity. In many cases, the quantization of a process can be performed auto matica lly by an analog-to-dig ital convene r.
The general-purpose digital computer is the best-known exa mple of a digital system. The major pans of a computer arc a memory unit, a central p rocessing unit, and input-output units.
Th e memory unit stores programs as well as input. output, and intermediate data. The ce ntral processing unit performs arithmetic and other data-process ing operations as specified by the program. The program and data prepared by a user are transferred into memory by means of an input device such as a keyboard. An o utput device, such as a printer, receives the results of the computations, and the printed results are presented to the user. A digital computer can ac- c ommod ate many input and output devices. One very useful device is a com munication unit that provides interaction with other users through the Internet. A digital computer is a power- lui instrument that can perform not only arithmetic computations. bu t also logical operations.
In addition, it can be programmed to make decisions based on internal and external condit ions.
There are fund amental reaso ns that commercial products are made with digital circuits.
Like a digital computer, most digital devices are programmab le. By changing the program in a programmable device, the same underlying hardware can be used for many different a ppli- cations. Dramatic cost reductions in digital devices have come abo ut beca use of advances in digital integrated circuit technology. As [he number of transistors that can be put on a piece of silicon increases to produce co mplex. functions, the cost per unit decreases and digital devices can be bought at an increasingly red uced price. Equipment built with d igital imegruted cir- c uits can perform at a speed of hundreds of millions of operations per second. Digital systems can be made to operate with extreme reliability by using erro r-correcting codes . An example of this strategy is the digital versatile disk (DVD), in which digital information representing video, audio, and other data is recorded without the loss of a single item. Digital information on a DVD is recorded in such a way that, by examining the code in each digital sample before it is played back, any error ca n be automatically identified and corrected.
A digital sys tem is an inte rconnection of digital modules. To understand the operation of
each digital module , it is necessary to have a basic knowledge of digital circuits and their logi-
cal function. The first seven chapters of this book present the basie tools of digital design, such
as logic gate structures, combinational and sequential circuits, and programmable logic devices .
Chapter 8 introduces digital design at the register transfer level (RTL). Chapters 9 and to deal
with asynchronous sequential circuits and the various integrated digital log ic families. Chapters
I I and 12 introduce commercial integrated circ uits and show how they can be connected in the
laboratory to perform experiments with digital circuits.
Sectio n 1.2 Binary Numbers 3
Amajortrendin digitaldesignmethod ologyistheuse of ahardwaredescriptionlanguage (HDL)10describeandsimulatethe functionality of adig italcircuit.AnHDLresemble sapro- gramminglanguageand is suitahlefordescribingdigitalcircuits in textualforrn.Itisusedto simulate adig italsystem10verifyitsope ration beforehardwareisbuilt in.Itisalsousedin conj unc tionwithlogic synthes is tools toautomatethedesign proc ess.Becau seit isimpo rta nt thatstude ntsbecomefamiliar withanHDL·baseddesignmethod ology,HDLdescriptionsof digital circuits arcpresented througho utthebook.WhiletheseexampleshelpIllustratethefea- turexIIfanHDL.they alsodemonstratethe bestpracticesused byindustryIuexploitHDLs.
Ignoranceofthesepractices willlend10cute .but worthless.HDL models thatmay simulatea phenomenon.butthatcannothesynthes izedbydesign too ls. ortomodelsthatwaste silicon areaorsynthes izetohard warethatcannotoperatecorrectly.
Asprevio usly stated.dig ital syste msma nipulate discretequantities ofinformation that arc representedinbinary form.Operand sused for calculations maybeexpresse dinthebinary numbe rsystem.Otherdiscreteclements.includ ingthe decimal digits.arerepre sentedinbinary cedes.Digital circuits.also referred10as logiccircu its.proce ssdatabymeans of binary logic elements(logic gates)usingbinary signals.Quantit ies arestoredinbinary(two- valued)sror- age elements (flip-flops).The purposeof this chap teristointroducethe variousbinary co n- ceptscs aframeofrefere ncefor furtherstudyinthesucceed ingchapters.
1. 2 BINAR Y NUMBERS
Adecimalnumbe rsuchas 7.392 represents aquantityequal to7thousand s.plus 3hundreds.
plus9lens.plus2units.The thousa nds.hundreds. etc.. arepower!'>of 10impliedbytheposi- tionofthe coefficientsinthenumber.Tobemore exact.7.39 2 isa shorthand not ationfo rwhat sho uld bewrittenas
7XIO~
+ -'
X102+
t} X10'+
2X10°Howe ver.theconventionisto writeonlythe coefficientsand.fromtheirposition.deduce the necessarypowersof10.Ingeneral.anumberwithadecimalpointisrepresented byaseries ofcoefficients:
Theccefflcie msejarcany ofthe 10 digits(0.I.2•. . ..9).and the subsc riptvalucjgives the place value and.hence.the power of10bywhichthecoefficientm ust hemultipl ied.Thus.the preceding decimalnumbercanheexpressedas
IO-'a~
+
lO~a...+
10\ )3+
I02al+
IOta ]+ IOlltl()+
10-1"_1+ 1O-2u_2+
10-3°_3 Thedecimalnumbersystemis said10heofbase,orradix.10 becauseituse s10 digitsand thecoefficients aremultiplied bypow ersof 10.Thebinarysystemisa different numbe rS)'S-tern.The coe fficientsofthe binarynumbersystemhaveonlytwo[Kls ..ible values:0andI.
Eachcoefficie ntu)ismultiplied by2).andthercsultsareadded toobtainthedecim alequiv- alentof thenumber.TheradixpointIe.g ..thedecimalpointwhe n 10istheradix) distingu ishes positivepowersof10fromnegative powers of10.Forexample.thedecimalequivalentofthe
4 Chapter 1 Digital Syste ms a nd Bin ary Numb er s
binary num ber 11010.11 is 26.75, as show n from the multiplic ation of the coe fficients by pow- ers o f 2 :
I x 2
4+ I X 2 3 + 0 X 2 2 + I X 2 1 + 0 x 2° + I X 2- \ + I X 2- 2 = 26.75 In genera l. a numbe r e xpressed in a base-r system ha s coefficie nts multiplied by powers of r:.
a
lt' ,"+ a" _I ,,,,-1 + .. . +
{l2, ,2+ ai " + ao + a_ I , , - 1
-2
+ + -.
+
a_2" ... a_ m'TTh e coe ffic ients
a}range in value fro m 0 10
T -I . To distinguish be twee n numbers of d iffer- ent bases, we enclose the c oefficients in parentheses and write a subscript equal to the base used (exce pt some times for decimal numbers. where the co ntent makes it o bvious that the base is decim al). An example of a base-S number is
(4021.2)5 = 4
X53 +
0 X52 + 2
X51 +
Ix 5° +
2 X5-1 = (5 11.4) 10
The c oefficie nt values for base 5 c an be only O. 1, 2, 3. and 4 . Th e octal number system is a base-S system that has e ight digits: 0, 1, 2. 3, 4, 5, 6. 7. An exa mple of an oc tal num ber is 1 27.4. To determine its equivale nt dec imal va lue. we ex pand the num ber in a po wer series with
a base of 8:
( 127.4)8:::: I X 8 2 + 2 X 8 1 + 7 X gO + 4 X 8- 1 = (87.5) 10
Note that the di gits 8 and 9 cannot appe a r in a n octa l num ber.
It is customary to borrow the needed r digits for the coe fficients from the decimal sys tem when the base of the number is less than 10. The letters of the a lphabet a re used to supplemem the 10 decimal digits when the base of the num ber is grea ter than 10. For e xample, in the hexadecimal (base - to) num ber system, the first 10 digits are borrowed from the dec imal sys - tem. Th e letters A, B. C, D, E, and F are used for the digits 10. I I, 12, 13, 14, and 15. rcspcc - live ly. A n exa mple of a hexadecimal num ber is
( B65F) ltl = 11 X 16 3 + 6 X 16 2 + 5 X 16 1 + 1 5 X 1 6° = (46.687) 10
As noted before. the digits in a binary number are called bits. When a bit is equal to O . it does nO I co ntribute 1 0 the s um during the conversion. Therefor e, the co nve rsion from binary to dec- imal c an be obtained by add ing o nly the numbers with powers of two corresponding to the bits thai are equal to I . For e xample,
( 1lOJO lh = 32 + 16 + 4 + I = (53) 10
The re are four l 's in the binary number. The correspo nding decimal num ber is the sum o f
the four pow ers of two. The first 24 numbe rs obtained from 2 to the power of n arc listed in
Tab le 1. 1 . In computer work, 2
10is referred to as K (kilo), 2 2 0 as M (mega), 2 30 as G (giga) ,
and 2 40 as T (tera). Thu s. 4K = 2 12
:=4,096 and 16M = 2 2 4 = 16.777.216. Compute r ca-
pacity is usually given in bytes. A byte is eq ual to eight bits and can accommod ate (i.c., repre-
scnt the code of) one ke yboard c haracte r. A computer hard disk with four gigabytes of storage
has a capacity of 4G = 2 32 bytes (approximatel y 4 billion bytes).
Section1.3 Number-BaseConversions 5
Tablet.1
PowersofTwo
n Z" n Z" n Z"
0 I
,
256"
65.536I 2 9 512 17 131.072
2 4 10 I.O~~ 18 26~.I~
3 8
"
2.0·111 19 52~. 28 84 ie 12 4.1..196 20 1.048.576
,
32 13 8.192 21 2.097. 1526 64 14 16.384 22 4.194.3~
7 128
"
32.768 23 8.388.608Arithmeti coperationswithnumbersin baser followthe samerules as fordecimal num- ber s.When a baseother thanthefamiliarbase10isused.onemusthecarefultouse only the r-allo weble digits.Examplesofaddition.subtraction.and multiplicationof two binarynum- bersare asfollows :
augend: 101101 minuend: 10 1101 multiplicand : 101 1 addend: +100111 subtrahend: - 100111 multiplier: ~
sum: 1010100 difference: 000110 1011
0000 1011 product: llD lll The sumoftwobinarynumbersis calc ulated by the same rulesasin decim al.exceptthat thedigits of the sum inanysignificantposition canbeonly 0orI.Anycarry obta inedina give n significantpositionisused bythepairof digitsonesignificant position higher.Subtraction is slightlymorecomplica ted.Therules arestill the sameax in decimal.except Ihaltheborrowin agivensignificantpositionadds210aminuenddig it.fAborrow in thedecimalsystemadds 10toaminuenddigit.)Multiplicationis sim ple:ThemultiplierdigitsarealwaysIor0:there- fore.thepartialprodu ct sarc equaleithertothemultiplicandortoo.
1.3 NUMBER-BASE CONVERS IONS
Theconve rsionof a numberinbaserto decim al isdoneby expandingthenumberinapower seriesandaddingallthe termsas show npreviously.Wenowpresenta general procedurefor thereverseoperatio nof conve rtingadecimalnumberto anumberin baser.Ifthenumberin- cludesa radixpoint. itisnecessarytoseparatethenumber intoan integerpartanda fraction part.sinceeach partmU~1beconverted differently.Theconversionof adecim alinteger10anum- berinbase,.isdone bydividingthenumber and allsuccessivequotie ntsbyrandaccumulat- ingtheremainders.Thisprocedureisbestillustratedbyexample.
6 Chapter 1 Digital Systems and Binary Numbers
Con vert decimal 4 1 10 bin ary. First, 4 1 is divided by 2 to give an intege r quoti en t of 20 and a re mainde r of!. The n the quotient is agai n divided by 2 to give a ne w quotien t a nd remainde r.
Th e proc ess is continued until the integer quoti ent becomes O . Th e coefficients of the desired bin ary number are obt ained from the remainders as fo llows :
Int eger
Quot ient Remainder Coefficil'nt
4 1 /2
:=:2 0 + l
Uo :=:1
20/2 = 10 + 0
UI= 0
10 12
:=:5 + 0
U2 :=:0
512 = 2 + ,
1 U3 :=:1
212 = 1 + 0
U4 :=:0
112
:=:0 + ,
1 (.15 :=:1
Th er efore , the answer is (4 1) 10
= (USU4UYI2(.1I Uoh :=:( 10 100 1 h.
Th e ar ithme tic pr ocess can be manipul ated more conve niently as foll ows:
Integer 41 20 1 0 5 2 I
o
Remainder
I
o o
I
o
I 101001 = answe r
Conv ersion from decimal integers to any base-r system is similar to this ex am ple. except that divi sion is don e by r instead of 2.
•
Conve rt decimal 153 to oc tal. The required base ' is 8. First , 153 is divided by 8 to g ive an in- teger quotient of 19 and a rema inde r of 1. Th en 1 9 is di vided by 8 to give an intege r quo tie nt of 2 and a rem ainder of 3. Fin ally, 2 is divided by 8
10give a quotient of 0 and a rem aind er of 2. Thi s proc ess ca n be conve nie ntly man ipulated as follows:
153
19 I
2 3
o 2 = (H i ls
Section 1.3 Number-Base Conve rsio ns 7 The co nversio nofa decimal/ ra e liontobinaryisaccomplishedbya methodsimilar10that used forintege rs.Ho wever.multiplication isused insteadofdivision.andintegersinsteadof rema indersareaccumulated.Agai n.the meth odis bestexplainedbyexample.
·,a4tjiQ"'. •
Convert(0 .6875)JOtobinary.First.0.6875 ismullipliedby210giveanimeger andafraction.
Thenthenewfractio nismultipliedby 2togiveanew imeger andanew fractio n. Theprocess iscontinued untilthefract ionbecomes0oruntilthenumber ofdigitsha ve sufficient accuracy.
Thecoefficie ntsof thebinary numberareobtainedfrom theintege rsasfollows:
Integer Fraction Coefficien t
0.6875 x 2
=
I + 0.3750 (/-1= I0.3750 X2
=
0 + 0.7500 (/- 2=
00.7500 x 2= I + 05000 {I-~=
05000
x
2= I + O.UOOO "-4=Therefore.the ans ....eris(0.6875)10= (0.1I-111-21l-YI_4b:=. (0.1011
h
Toco nvertadec imal fraction10 a numberexpresse d inbaser,asimilarproced ureisused.
Ho we ver.multiplicat ionisbyr insteadof 2.andthe coe fficients foundfromthe Integersmay rangeinvalue from0 to r- Iinsteadof0 andI.
·"%1'9····
Convert(0.513)10 10 octal.•
0..513X8=4.104 0,10-1X8=0.832 0.83 2X 8= 6,6.56 0.656X8= 5.248 0.248 X 8= 1.98-1 0.984X8= 7.872
The answer.to sevensig nificant figures.isobtainedfromtheintege r pa rtoftheproduct s:
(0.5 13l lll= (OA06 517 ... lH
8 Chapt er 1 Digita l Systems a nd Binary Number s
The conve rsion of decimal numbers with both integer and frac tion parts is done by con- vening the integer and the fraction sepa rately and then combining the two answers . Us ing the results of Examples 1.1 and 1.3. we obtai n
(41.6875)10 - ( 1 0 100 1.10 11), From Exampl es 1.2 and 1.4 , we ha ve
( 153.5 13) 10 = (2 3 1.4065 17Js
•
1.4 OCTAL AND HEXADECIMAL NUMBERS
The co nversion from and to bina ry. octa l. and hexad ecim al plays an importa nt ro le in digital computers. Si nce 2 3 = 8 and 2 4 = 16, each octal digit corresponds to three binary digits and each hexadecimal digit corres po nds to four binary digits. T he first 16 numbers in the decimal, binary. octa l, and he xadecim al numbe r sys tems are listed in Table 1.2.
Th e co nvers ion fro m bin ary to octal is eas ily accomplis hed by partition ing the binary num- ber into groups of three digit s e ac h. starti ng from the binary point and proceedin g to the left and to the rig ht. The corresponding octal digit is then assign ed to eae h gro up. The follo wing exa mple illustrates the proc ed ure:
( 10 110 00 1 101 011 I II 100 000 110 ), = (26 153.7406),
2 6 I 5 3 7 4 0 6
T a bl e 1 ,2
Numbers withDifferent Bases
Ded m a l Binary Oct a l He xa d ec im a l
(base 10 ) (b a se 2) (b a se 8) (base 16 )
00 0000 00 0
01 0001 01
I02 0010 02 2
03 0011 03 3
04
010004 4
05
010105 5
06
011006 6
07
011107 7
0' 1000 10 8
09
1 001
II9
10
101012
A11 10 11 13
B12 1100 1 4 C
13
110115
D1 4 1110 1 6
EIS
lIll17
FSection1.5 Compleme nts 9
Convers ion from binarytohe xadecimal issimilar, exce ptthatthebinarynumber isdividedinto groupsof/ourdigils:
(10 2
1100 C
01If) 6
101[
Il
1111 F
OOlOh ""(:!C6B.F2)lfI 2
The correspondi ng hexadecimal(or ()cta!)digitfo r eachgro upofbina rydigilsisea.~ilyre- memberedfrom thevalueslistedin Table1.2.
Co nversio nfromoctalorhexadeci malto bina ryisdone by reversingtheprecedingproce- dure.Eachoctaldigil isconvened toirsthree-d igitbinaryequivalent.Simi larly,eachhexu- decimaldigit isconve rted to ih four-digitbina ryeq uiv alent.Theproced ure isillustrat edin thcfollo wi ngexa mples;
(673.12.). ~ (110 II I 011 (X)) 010 100),
6 7 3 I 2
•
aod
(306.D)16""(0011 O<XIO Ol IO I/O/
r z
3 0 6 D
Binarynumbersare difficultInwork withbecausetheyrequirethreeor fourlimes a..many digit..a..their decimalequivalents.Forexample,thebinarynumberIJ1111111111iseq uivalent to decimal.J095.Ho wever.digitalcomputersuscbinarynumbers,anditissome timesnecessary forthehumanoperatororuser toconuuumcatcdirectlywith the machinebymeansof suchnum- hers.Oneschemethatretainsthebinarysysteminthe computer. but red ucesthenumber ofdig- itsthehumanmustconsider,utili/estherelatio n..hipbetweentho:binarynumbersystemandIhe ucla l~lrhe xall e drnal:.)':. 1\:111.Bythi:.1I1\:lh"o.I.thchUI1l,u lt hil)k...illlenl1""foC lalor hcJl.a d....~irlla l
num be...andperformsthereq uiredcon version byinspec tion whendirec tco mmunication with themachinei..ncce....ary.Thu...thebinarynumber11111 11111 11has12digitsandis expressed inoctalas 7777 (.Jdigit s ) orinhe xadecimalasFf -F(3digits ).Duringcom municationbetween
people(aboutbinarynumbersinthe computerj. jhc fIClalor hexadecimalrepresentationismore
de..irable because it canbeexpre..sedmore compactlywithathirdoraquarter of the numbcr of digitsreq uiredfor(he equivale nt binarynumber.Thus.most computermanualsuseeitheroctal orhexadecimalnumberstospecify binuryquunthic...Thechoice betwee nthem isarbitrary, althoughhexadecimaltend..towinOUl,sinceitcanrcprc..cnra bytewith twodigits.
1.5 COMPLEMENTS
Complements arcu..cdindigitalco mputerstosimplifythe subtractionoperationand for log- icalmanipulation.Simplifyingoperationsleadstosimple r.lessexpensivecircuitstoimple ment theope rations.The reareIWOtypesofcomplementsfor eachbase-rsystem:theradix: co m- plementandthe diminished radixcomple ment. Thefirst isreferred to asther's com plement andtheseco ndasthe(r - I)'scomple ment.When thevalueofthebaserissubstitutedinthe name.the twotypesarereferredtoasthe 2'scomple mentandI'sccm pte men rforbinarynum- hersandthe 10\ complement and9's compleme ntfor decimal numbers.
10 Chapte r 1 Digita l Syste ms and Binary Numbers
Diminished Radix Complement
Give n a num ber N in base r having n d igits , the (r - I )' lo co mpleme nt of N is defined as (r" - I ) - N . For decimal numbers, r == 10 and r - I "" 9, so the 9' s complement of N is ( 10" - I ) - N , In this case. 10" repre sents a number that con sists of a single I followed by nO 's. 10" - I is a number represented by n 9 's. For e xample, if n "" 4. we have I~ = 10,(0)
and I~ - I "" 9999 . II follo ...s that the 9's complement o f a decimal number is obtained by
subtracting ea ch digit from 9. Here are some numeri cal e xamples :
The 9 's comple ment of 54-6700 is 999999 - 54-6700 "" ..$53299 . The 9' s co mplement o f 0 12398 is 999999 - 012 398 == 987601 .
For binary numbers.v "" 2andr - I "" Lso tbe l 's complemen r ofN is (2" - I ) - N . Agai n, 2
nis represented by a binary num ber that consists of a I follo
wed by nO's . 2
n -I is a binary number re presented by n I's. For example, if
11 ""4, ...e have 2
4 ""( l(X)()()h a nd 2 4 - I "" ( 1111 h Thus, the l's complement of a binary number is obtained by subtract ing eac h digit from 1. Ho we ver, wh en subtrac ting b inary dig its fro m I,
wc ca n ha ve e ithe r
I - 0 "" I or 1 - I == 0, which ca uses the bit to change from 0 to 1 or from I to 0, respec-
tively. Ther efore, the l's comp leme nt of a binary num ber is formed by changi ng l 's to D 's and O's to J's . The followi ng are some numerical examples:
The t's complemcnt of 1011OOO isO lOO I I I.
The I's co mpleme nt o f 0 101101 is 1010010.
The (r - I)' s compleme nt of octal or hexadeci mal numbers is obtained by subtracting each digit from 7 or F (decim al 15), respec tivel y.
Radix Complement
The r's complement of an a-digit number N in base r is defined a.. r n - N for N
"F-0 and as o for N "" O . Comparing with the (r - I )' s complement. we n ote that the r's complement is obtained by adding I to the {r - I )' s complement, s ince r" - N "" [ (r " - I) - N] + I.
Thus, the lO's co mpleme nt of deci mal 2389 is 7610 + I "" 76 11 a nd is obtai ned by adding I to the c's-co mple rnent value . The 2's comp leme nt of h inary 10 11 00 is 0 10011 + I "" 010 100 a nd is obtained by adding I to the t 's-co mple meru value.
Since 10 is a number represented by a 1 followed by
IIa 's, 10" - N,
which is the tu's co m- plement of N. can be formed also by leaving all least s ig nificant n's unch anged , subtrac ting the first nonzero least significa nt digit from 10, and subtracting all highe r significant digits from 9. Thu s,
the 10's complement o f 0 12398 is 98 7602 and
the In's complement o f 24-6700 is 75 3300
Sectio n 1.5 Complements 11 The lO'sco mplementofthefirst numberis obtained bysubrrccting 8from10 inthe leastsig- nificantpositionandsubtractingallotherdigitsfrom 9.The-lO'scomplemen toftheseco nd numberisobtained byleavingthetwoleastsig nificantO'sunch anged. subtracting 7from10, andsu btract ing the othe r threedig its from9.
Similarly, theZ'scomple mentcanbeformedbyleavingallle astsignificantu'sandthefirst Iunch angedandreplacin gI'swithO'sand0\ withJ'!'.inallotherhighersignificant digits.
Forexample,
the- :!'scomplement of1101100is0010100 and
the2\ com ple mentof01101JIis1001 001
The 2's complementofthefirstnumberisobtainedbyleavingthetwo leastsignific ant O'sand thefirstIunchangedandthenreplacingl'swithO's andO'swithlsinthe otherfour mostsig- nificuntdigits.The 2's complementof theseco nd numberisobtained byleavingthe leastsig- nific ant Iunchangedandcomplementingallotherdigits.
Intheprevious defin itions ,itwasassumedthaithe numbersdidno t havea radix point.If theorigina l numberNcontains arad ixpoint. thepointshouldberemo vedtemporarilyinorder 10formthe-r'sor(r- I)'s complement.Theradix pointisthenre storedtothecomplement- ed numbe rin thesamerelativeposition.It isalso worth mentioningthatthecomple ment of the comple me ntresto resthenumbe rto its originalvalue. To seethisrelatio nship.notetha t the r's comple me nt of N is r" - N, so that the compleme nt of (he complement is
rn - (r" - N)=Nandis eq ualtotheoriginalnumber.
Subtraction with Complements
The direct methodof subtractiontaught inelementary schoolsusesthebOrTOWconcept.In this melhod.wehO rTOWa Ifromahighe rsigrnficumposition whenthemin uenddigit is smaller (hanthesubtrahenddigit.Theme thodwor kswell whenpeopleperform subtractionwithpaper andpencil.Howe ver.whensubtractionisimpleme nted withdigital hardware.the-methodisless efficie ntthanthemeth odthatuses com plements.
The subtractionoftwoII-digitunsigne-dnumbers1\.1 - ,Vin baserca nbe doneasfollows:
I. Add the minuendAI10ther's comple me ntofthe su btra hendN.Mathematically, M +(r" - N) = ,\1- N + r",
2. If!of2 N,the sumwillproduce anendcarryr",whichcanbediscarded : whal isleftis the resultM- N.
3. IfM <N,the sum doc snotprod uce anendcarry andisequalto r"- (N - M), whichisther'scomplcmcnrof(N - AI).Toobtain the answer in afamiliarform.tak e ther'scomplementof (hesum and place anegative sign in front.
12 Chapter 1 Digital Systems and Binary Numb ers The following examples illustr ate the procedure :
Using 10's complement. subtract 72532 - 3250.
M = 72532
lO's complement of N
=+ 96750 Sum = 169282 Discard end carry lOs = - 1 0ססoo Answer = 69282
Note that M has five digits and Nhas only four digits. Both numbers must have the same num- ber of digits, so we write N as 03250. Taking the 10's complement of N produces a 9 in the most significant position. The occu rrence of the end carry signifies that M
~N and that the result is therefore positive.
•
Using lO's complement, subtract 3250 - 72532.
M = 03250 l O's c omplement of N = + 27468 Sum
=307 18
There is no end carry, Therefore, the answer is - ( IO's complement of 307 18) = - 69282.
Notc that since 3250 < 72532, the result is negative. Because we are dealing with unsigned numbers, there is really no way to get an unsigned result for this case, When subtracting with complements. we recognize the negative answer from the absence of the end carry and the complemented result. When working with paper and pencil, we can change the answer to a signed negative number in order to put it in a familiar (a nn .
Subtraction with complements is done with binary numbers in a similar manner, using the procedure outlined previously.
•
Given the two bin ary numbers X = 1010100 and Y =
1ססoo11,pe rform the subtract ion
(8)X - Y and (b) Y - X by using 2's complements.
(a ) X'"
2' s complementofY'"
Sum'"
Discardendcarry2' '"
AII.m'er:X- Y '"
(b) y ",
2' "com ple mentof X""
Sum=
1010100
+J!!..!..!..!Q!
10010001 - / ()()()()()()()
1)()IOOOI
1000011 +0101100
1101111
Section1.5 Com plements 13
Thereis110 l'" dcarry.Therefore,till'answerhY - X = -(2'scomple tucmof 1101III) = -OOIOlXII.
Subtraction(If unsigned numberscanalso be donebymeans of the(r - J)' scomplement.
•
Rememberth<llthe (r - I)'s complement is one lessthan ther'scomplement.Becauseof this,theresultof:u.ldingrheminuend tothe complement ofthe subtrahend producesasum that isonelessthanthecorrectdifference whenntilendcarryoccurs.Removingtheendcarry and addingI to thesumisreferred10as anend-aroundcarry.
M1tAmQIII:1I
RepeatExample1.7, bUIthistimeusingt'scomplement.
fa) X - Y= 1010100- 100001 I
X = 1010100 I' scomplementof
Y
=+
OJ11100Sum= lOOIOfX){) End-around carry=
+
I Al1.m er:X- Y= 00 HX)() I (b)Y- X= jOfX){) 11- IOlOHXIY = 100XIOII
I'scomr l cment of X = + 0101011
Sum= 1101110
There isnoendcarry.Therefore.theanswerisY- X""-(I'scomplementof1101110 )=
-00toooI.
•
NotethaIthenegative resultj'i.obtainedhytakingtheI's complementof the sum,sincethisis thetypeofcomplement used.Theprocedure withend-aroundcarryis alsoapplicabletosub- tractingunsigneddecimalnumbers with9'scomplement.
14 Chapter 1 Digital S ystem s a nd Binary Numbers 1.6 SIGNED BINARY NUMBERS
Positive integer s (including zero ) can be represented as unsigned numbers. However, to re p- resent ne gative integers, we need a notation for negative values. In ord inary arithmet i c , a neg- ative number is indicated by a m inus sign and a positive number by a plus sig n. Because of hardware limita tions. co mputers must re present e verything with binary digits. It is customary to represent the sign with a bit placed in the leftmost position of the number. The convention is to make the sign bit 0 for pos itive and I for negative.
It is important to realize that both signed and unsigned binary num bers consist of a string of bits when represented in a comp uter. The user determines whether the number is signed or unsigned . If the bina ry numbe r is sig ned, then the leftmost bit represents the sign and the rest of the bits re present the number. If the binary number is assumed to be unsigned. then the left- most bit is the most significant bit of the number. For example, the string of bits 0 100 1 can be considered as 9 (unsigned binary) or as + 9 (signed binary) because the leftmost bit is O . The string of bits 11001 represents the binary equivalent of 25 whe n considered as an unsigned number and the binary equivalent of - 9 when considered as a signed number. This is becau se the 1 that is in the leftmost position designates a negative and the other four bits represent bi- nary 9. Usually, there is no confu sion in identifying the bits if the type of re presentation for the number is known in advance.
The represe nta tion of the signed numbers in the last example is re ferred to as the signed- ma gnitude convention. In this notation, the number consists of a magnitude and a symbol ( + or -) or a bit (0 or I) indicat ing the sig n. This is the representation of signed numbers used in ord inary arithmetic. Whe n arithmetic o perations are imp le mented in a comp uter, it is more convenie nt to use a different sys te m, referred to as the signed-complement system, for repre- senting negative numbers. In this system, a negative number is indicated by its complement.
Whereas the signed-magnitude system negates a number by changing its sign, the signed-com- plcrncnr system negates a number by taking its complement. Since positive numbers always start with 0 (plus) in the leftmost position . the complement will alwa ys start with a I, indicating a negative number. The signed -complement system can usc either the l 's or the 2's complement.
but the 2'" complement is the most common.
As an example, co nsider the number 9, represented in binary with eight bits. + 9 is repre- sented with a sign bit of 0 in the leftmost position, followed by the binary equivalent of 9, which gi ves 0000 100 1 . Note that all eight bits must ha ve a va lue; therefore, O's are inserted fol- lowing the s ign bit up
10the first I. Althou gh there is o nly o ne way to represent + 9, there are three di fferent ways to represent - 9 with eight bits;
signed-magnitude representation:
signed- f's-complement reprcsemano n:
signcd-Z's-c omplement re presentation:
1000 100 1 11 110110 11 110 11 1
In signed-magnitude. - 9 is obtained from + 9 by changing the sign bit in the leftmost positio n
from () to I. In signed-Fa complement, - 9 is obtained by c omplementing all the bits of + 9,
including the sign bit. The signed-J's-complc mcnt representation of - 9 is obta ined by taking
[he 2's complement of the positive number, including the sign bit.
Section 1.6 Signed Binary Numbers 15
Table 1.3
SJgntd Binory Numbers
Slgned.2'$ Slgned.1 '$ Signed
Oedm a l Comp lem ent Co mple ment Magnitude
+7 0111 0111 01II
+h 0110 0110 0110
+' 0101 0101 0101
+4 0100 0100 0100
+3
oon
00 11 00"+2 0010 0010 0010
+1 OO()[ 0001
ooo t
+0 O(JU(} 0000 00'"
-0 IIII 1000
- I 1111 1110 1001
-2 1110 1I0! 1010
-.,
1101"'"
lOll-4 "00 1011
"'"
- ,
1011 lOW 1101-6 1010 1"'1 1110
-7 100! 1000 1111
-,
IUOOTable: 1.3 listsall possib lefour-bit signed binar ynumbers inthethree representations.
Theequiva lent decimalnumberisalso shown forreference .Notethatthepositivenumbers inall threerepresentationsare:identicalandhave0in thelefuuost position.The signed-z's- complementsystem hasonlynnerepresent ationforO.whichisalwayspositive.Theother two systems haveeithera positive0oranegat iveO.somethingnotencounte redin ordinary arirhmcric.Notethatall negativ enum bershave a I intheleftmostbitpositio n:thatisthe waywedistinguishthem fromthepositivenumbers.Withfourhits.wecanrepresent16binary numbers.Inthe sig ned-magnitudeandthels-ccm plernentrepresentations.thereare eight positivenumbers and eight negnnvenumber s.includingtwozeros.In the2's-complement representatio n. the reareeight positive num bers,includingone zero. andeig htnegati ve numbers.
The signed-magnitudesystem isused inordi naryarithmetic.but isawkwa rdwhenem- ployedincomputer arithmeticbecause of theseparate handlingofthe signandthemagnitude.
Therefore.thesigned-complementsystem Isnormallyused.TheFscomplementimposessome difficultiesandisseldo m usedforarithmetic operations.Itisusefu las a logicaloper ation.
sincethe changeofIto0or010 Iisequivale nrroalogicalcomple ment operation.aswillbe shownin thenext chap ter. The discus..ion ofsigned binary arithmeticthat followsdealsex- clusivelywiththesigncd- z's-cornple ment representationofnegative numbers.Thesamepro- cedurescanheapplied tothesigued-!"..-complemer usystem byincludingtheend-around carry asis donewithunsignednumbers.
16 Chapter 1 Digital Systems and Binary Numbers
Arithmetic Addition
The addition of two numbers in the signed-magnitude system follows the rules of ordin ary arith - metic. If the signs are the same, we add the two magnitude s and give the s um the common sign.
If the signs are different, we subtract the s ma ller magnitude from the larger and give the diffe r- ence the sign of the larger magnitude. For example, (+ 25) + ( - 37) = -(37 - 25 ) = - 12 a nd is done by subtrac ting the smaller magnitude, 25. fro m the larger magn itude, 37, a nd a ppending the sign of 37 to the result. Thi s is a proce ss tha t requires a co mparis on of the signs and magni tude s and then performi ng either addition or subtrac tion. Th e same procedu re appli es to binary numbers in signed-magnitude representa tio n. In contrast, th e rule fo r adding numbers in th e s igned-co mple me nt system doc s not require a com pa rison or sub- tract ion. but only additio n. The proce d ure is ve ry simple and can be stated as follow s for binary nu mb ers:
The additi on of two sig ned binary numbers with negative numbers represe nted in signed- Z's -complement forrn is obtain ed from the add ition of the two numbers , including the ir sign bits.
A carry out of the sign-bit position is discarded . Numerical examples for addition follow :
+ 6 00000110 - 6 11111010
+ 13 00001101 + 13 0000 1101 + 19 000 100 11 + 7 000001 11 + 6 O ()()OO 110 - 6 111 11010 - 13 1111 0011 - 1 3 111100 11 - 7 1111100 1 - 19 1110 1101
Note that negativ e numbers must be initially in Z's -complement form and that if the s um ob- tai ned after the additi on is negative, it is in z 's-compleme nt form .
In ea ch of the four cases, the operation performed is add ition with the sign bit incl uded . Any carry out of the sign-bit position is discarded, and negative re sults are automatically in z's- comple ment form.
In order to obta in a correct answer, we must ensure that the result has a s uffic ient number of bits to accommodate the sum. If we start with two u-bit numbers and the sum occupies n + I bits, we say that an ove rflow occ urs. When one performs the addi tion with paper a nd pencil , an overflo w is not a problem, becau se we are not limited by the width of the page . We j ust add another 0 to a positi ve num ber or another I 10 a negative num ber in the most signifi- ca nt position to exte nd the num ber to n + I bits an d then perform thc addi tion. Overfl ow is a problem in computers beca use the number of bits that hold a num ber is finite, and a res ult that exceeds the finite value by I can not be accommoda ted.
The compleme nt form of represe nt ing ne gative numbers is unfa miliar to tho se used to the
sig ned-mag nitude sys tem. To determine the val ue o f a negative number in signcd-z 's comple-
ment, it is necessary to convert the num ber to a positive numbe r to place it in a more famil iar
form . For ex ample, the signed binary number 1111100 1 is negati ve because the leftmost bit is
1. Its 2's complement is 00000 111, which is the b inary equiva le nt of + 7. We therefore recog-
ni...
'ethe orig inal negative number to be equal to - 7.
Sect io n 1.7 Bina ry Codes 17
Arith metic Subtract io n
Subtractionof
''''''0
signed binarynumberswhennegativenumbersareinJ's-cornplemcn r form is simpleandcan hestatedasfollows:Takethe2'scomplement ofthesubtrahend (includingthe sign billandadd it to the minuend (includ ingthe signbiu.Acarryout ofthesign-bit positionis discarded.
Thisproced ureisadoptedbecause a subtract ionope rationcan he cha ngedIIIan addi tion ope ration ifthesignof thesubtrahend ischa nged . as i!'. demo nstra tedbythefollowing relationship:
(±A) - (T8) (±A)- (-8)
(±A)T(-8):
(±A) T (+8).
Butchangingapositive numberto a negativenumberiseasilydonebytakingthe 2'scomple- mentof thepositivenumber.Thereverseisalsotrue, becausethecomplementof a negativenum- berincomplementform produ cesthe equivalentpositivenumber.Toseethis. considerthe subtrac tion (-6)- (-13)""+7. Inbinary with eight bits,this operation is wriue n as (11111010- ll llO(}J I).The subtraction i!'. changed to additionbytaking the 2'scomplement ofthesubtrahend(-13),giving(+13).Inbinary,thisis11111010
+
00001101= 100000 11L Removingtheendcarry, we obtainthe correctanswer:00000111(+7).IIisworth notingthat binarynumbersinthe signed-complementsystemarc added and sub- tracted bythesamebasic additionandsubtraction rules asunsignednumbers.Therefore,com- putersneedonlyone common hardwarecircuit tohandleboth types ofarithmetic.Theuser or programm er mustinterprett heresultsof suchaddi tionor subtraction differently,depe ndingon whetheritisassumed thaithenumbers aresignedor unsigned .
1.7 BINARY CODES
Digitalsystemsuse signalsthathave twodistinctvalue..and circuit elementsthai havetwosta- bleslates,Thereisadirect analogy amongbinary signals.binary circuitelements,andbinary digits.Abinarynumber of/Idigits,forexample,mayberepresemcdbynbinary circuitele- mems.each having an outpu tsignalequivale nt100orI.Digitalsystems representandma- nipulate notonly binarynumbe rs,butalsoman y otherdiscrete elemen tsof informatio n.Any discret eelementof inform ation thatisdistinct amongagroupofquanti tiescanherep resented witha binarycode(i.e.,apatternofD'sand I's).The codesmustbein binarybecause, in today'stechn ology,only circuitsthutreprese nt and manip ulate patte rnsofD'sand I'scanbe manufacturedeconomicallyforuseincomputers. However.itmustberealiz ed that binary codes merelychangethe symbols, nor rhemeaning oftheelements ofinformationthat they rep- resent.IfweInspectthebitsofa com puteratrandum,wewillfindthatmostof thetimethey represe ntsometype ofcode dinformationrather thanbinarynumbers.
Ann-bit binary code is a groupof11bitsthatassumesupto
r
distinctcombinationsofl's and 0'5.witheachcombinationrepresentingoneelememof the setthatisbeingcoded.Asci offourelem entscanbecoded withIWObiu.witheach eleme ntassigned oneofthefollowing bitcombinations:00.01.10.11.Asetofeightelem entsrequires athree-bitcod e anda setof18 Chapte r 1 Digital S yst em s a nd B inary Numb er s
16 elements req uires a four-bit code . The bit combinat ion of an n-bit code is determi ned from the count in binary from 0 to 2" - I. Each element must be assigned a unique binary bit com- bi nation, and no two elemen ts can have the same value ; otherwise, the code assignmem will be ambiguou s.
Although the m inimum number of bits required to code 2" distinct quantities is n, there is no maximum number o f bits that may be used for a binary code. For example. the 10 decima l digits can be coded with 10 bits, and each decimal digit can be assigned a bit combination of nine O's and a I. In this particul ar binary code , the digit 6 is assigned the bit combination 0001000ooo .
BCD Cod e
Although the binary number system is the most natural syste m for a computer, most people are more accustomed to the deci mal system. One way to resolve this difference is to convert dec - imal number s to bi nary, perform all arith metic calculations in binary, and then convert the bi- nary results back to decimal. Th is method requires that we store decima l numbers in the co mputer so that they can be co nverted to b inary. Since the computer can accep t o nly binary values. we must represent the decimal digits by means of a code that contains l 's and D 's. It is also possible to perform the arithmetic operations directly on decimal numbers when they are stored in the computer in coded fonn .
A binary code will hav e some unassigned bit co mbinations if the number of elements in the set is not a multiple power of 2. The 10 decimal digits form such a set. A bi nary code that dis- tinguishes among 10 elements must contain at lea..
tfour bits. hut 6 out of the 1 6 possible com- binations remain unassigned . Different binary codes can be obtained by arranging four bits into 10 distinct combin ations. The code most commonly used for the decimal digits is the straight binary assignment listed in Table 1.4. This scheme is called binary-c odeddecimal and is commonly referred to as BCD. Other decimal code s are possible anda few of them are pre- sented later in thi.. section.
Table 1.4
Binary-Cod«JD«.lmol (BCD)
Dedmal
Symbol
o
1
2 3 4 ,
6 7 8 9
BCD
Digit
ססoo ()()()1
0010
0011
01 00
0101
0110
0 11 1
1()()()1001
Section 1.7 BinaryCodes 19
Table 1.4 givesthefou r-bit code Foronedecima ldig it.Anumber withkdecimalJigil swill requ ire-t*bit"innCD.[)..,c;"",1.1% isrcp ,·cs ","cd;11nCD wid, 1.2hit.s ".s(lOll 10010110. witheachgroupof4 bitsrepresentingonedeci ma ldigit.AucctmutnumberinBCD Isthe
"ame asit"equ ivalen tbinarynumber onlywhen thenumber isbetween0and 9.ABCDnU IIl- bergreaterthan 10looksdiffe rentfromjhequivalent binarynumber.eventhough bothcon- tainf'sandO'~.Mo reo ver.the binary combinatio ns 1010 th rough IIIIarcnotusedand ha ve nomeaning inBCD.Con..ide rdecimal185anditscorrespon dingva lue inBCDandbinary:
(185)1f)= ((XXII HJ()(l0101hK'D= (1OlllOOlh
The BCDva luehas12bil"toencode the charactersofthedecimalvalue.hUIthe eq uivalent bina rynumberneedsonly8bits.IIi:..obvio us thattherepresentationofaBCD numberneeds morebitsthenil';.equivalent binaryvalue.Ho wever.the reis anadvantageintheuse ofdeci - malnumbers. becausecomputerinputandoutp ut dataaregenera ted bypeoplewhousethedec - imalsystem .
IIisimportant torealizethatBCDnumbersliredecimalnumbers and nOI binarynumbers.
althoug hthey usebitsintheir representation.Theonly diffe rencebetweenadecimalnumber andBCDistha tdecimal"arcwnuenwiththesymbol..O.I.2•...•9 andBCD numbersuse thebinarycode0000.0001.0010.. ...1001.Thedecimal value isexactly thesame.Decimal 10isrepresentedinBCDwitheightbit.sas00010000 anddecimal15as00010101.Thecor- re spondingbinary value...are 1010and II1Iand have onlyfo urbits.
BCD Addition
Conside rtheadditionoftwo decimaldigits in BCD .lOgethe r withapossiblecarryfrom apre- viousless significant pairofdigits.Since cadi digit doe snot exc eed 9.thesumcannotbe greaterthan9
+
9+ I = 19...ith theI beingaprevious carry.Supposewe addtheBCD dig.itsa..ifthe ywerebinarynumbe rs.Then the binary sumwill produceare sultintherange from 0 to19.In binary.thi..range willbefrom (XKX) to10011.butin BCD. itisfro m0000to I 1001.with thefirst(i.e.•letrmo..t)Jbeinga carryandthenextfo ur bitsbeing theBCD sum.
Whenthebina ry sum is eq ualto orlessthan I(X)I(witho uta carry ).the correspondingBC D digit is correct.However.whe nthebina ry sum is greaterthanorequ al 1010IO.theresultis an invalid BCDdigit.Theadditionof 6= (0110)210 thebinarysumconvertsh rothecorrectdigit andalsoproduce .. a carryasreq uired.Thisisbeca useacarry in the mostsignificant bitposi- tionofthebinarysurnandade cimalcarrydiffer by16 - 10=6.Con sider thefoll owing threeBCDadditions:
~ 0100 ~ 0100 8 1000
+5 +0 101 +8 +1000 +9
--.lQQ!
9 1001 12 1100 17 10001
+0110 +0110
100 10 10111
Ineachcase. thetwoBCDdigitsare addedas iftheyweretwobinarynumbers.If the bina ry sum is greeterthanorequa lto10 10.weadd0110to obtainthecorrect BCDsumanda carry.
Inthefirstexa mple.the sum i.. eq ual109andisthecorrec tBCDsum.In theseco nd example.
20 Chapter 1 Digita l Sys tems and Binary Numbe rs
76()
1 84 + 576
I I
000 1 1 000 0 100 + 0 10 1 0 111 0 110 0 111 1 0000 1 0 10 0 110 OllO 0 111 Ol iO 0000 Binary sum
Add 6 BC D sum
the binary sum produ ces an invalid BCD digit. The addi tion of 0 110 produ ces the correc t BCD sum, 00 10 (i.e., the number 2), and a carry. In the third example, the binary sum prod uce s a carry Th is condi tio n oc curs whe n the sum is greater tha n or equal to 1 6. Alth ough the other four bits are less tha n jOO I. the binary sum req uires a correc tion because of the c arry. Add ing OliO, we obtain the required BCD sum Ol ll (i.e.. the numbe r
7)and a BCD carry.
Th e add ition of two n-digit unsigned BCD num bers follows the sa me proc edure . Co nsider the addition of 1 84 + 576 = 760 in BCD:
BCD
Th e first , least significa nt pair of BCD digits produces a BCD digit sum of 0000 and a carry for the next pair of digit s. The sec ond pa ir of BCD digits plu s a previous carry produ ces a digit s um of a 11 0 and a carry for the ne xt pair of digits.The third pair of dig its plus a carry produces
a binary sum of 0 111 and doe s not req uire a correction.
Decimal Arithmetic
Th e representation of signed decimal numbers in BCD is similar to the rep resentation of sig ned num be rs in binary. We ca n use either the famil iar signed- magnitude syste m or the signed-com- plement sys tem. The s ign of a deci mal num ber is usua lly rep resented wit h fo ur bit s to conform
to the four-bit code of the dec imal dig it s. It is customary to des ign ate a plu s with fo ur O's and a minus wi th the BC D equivalen t of 9 , whic h is 1 00 1.
Th e signed- magnitude system is seldom used in computers. The signed-c omplement system ca n be eithe r the 9's or the lO's compleme nt, but the lO's comp leme nt is the o ne most often used. To obtain the lO's co mplement o f a BC D n um ber, we first lake the 9 's c omplement and then add 1 to the least significan t digit. Th e 9's comp lement is calc ulate d fro m the subtrac tio n of each di git from 9.
The procedur es de ve lope d for the sig ned-2's-comple ment sys tem in the pre viou s sec tio n also app ly
tothe signed- IO's-co mp le ment sys tem for decimal numbers . Add itio n is don e by summi ng all digits, incl uding the s ign digit, and discard ing the e nd carry. Th is o pe ration assume s that a ll negat ive numbers are in lO' s-co mple me nt fonn. Conside r the add ition ( + 37 5) + ( - 240) = + 135, done in the signed-c omp leme nt syste m:
o 375
+9 760
o 1 35
The 9 in the leftmost position of the second number represents a mi nus, a nd 9760 is the 10's comple ment of 0240. T he two num be rs are added and the end carry is d iscard ed to obtain
+ 135. Of course, the decim al numbers inside the computer, includin g the s ign digits, must be
in BCD. The add ition is done with BCD digits as de scribed pre viously.
Section 1.7 Binary Codes 21
Thesubtractionof decimalnumbers. eitherunsignedorintheslgncd- tu's-com pleme nt system.isthesa meas in the binary case:Takethe10'l>comple mentofthesubtrahendandadd it to theminuend.Many compute rshavespecialhard ware10perfo rm ari thmeticcalculations directlywit h decimalnumbers in BCD.The userofthe computerca nspecify programmed instructions10perform thearithmeticoperationwith decimalnumbersdirectly.without ha ving 10conve rtthem tobina ry.
Oth er Decimal Codes
Binarycod esfordecimaldigitsrequire a minimumoffou rbibperdigit.Many differentcodes canbeformulatedbyarrangingfourbitsinto10distinctcombinations.BCD and thn..-cothe r representativecode s areshownin Table1.5.Eachcode uses only10outofapo ssible16bit combinationsthatcanhe arrangedwithfour bits.Theothersixunused comb inat ionshaveno meaningandshouldbeavoided.
BCDandthe2·UIcodean:examples
or
weightedcodes.Ina weightedcode.eachbitposition is assigned a weightingfactorinsucha wayIhateach digit canbeevaluatedbyadding thewei~hb ofalltheI'~inthecodedcombination.TheBCDcodehasweight s of8.4.2.andI.whichCOITe-spe nd tothepower-of-twovaluesof eachhit.Thebitassignment0110.forexample.is interpreted bythe weightstorepresentdccimalfbecause8x0
+
4x 1+2x I + I x0==6.The bit combination110 1.whenweightedbytherespectivedigits2421.gives thedeci malequivale ntof 2 x I+
4 x I+
2x0 + Ix I==7.Notethatsome digits canbecode d in twopossible waysin the242 1code..Forinstance.decimal4 canbeassigned tobitcombination0100or1010.since bothco mbinationsadd uptoatotalweightof 4.
Table1.5
four Differtmt Binary Codesfor the Decimal Digiti
Decimal BCD
Digit 8421 2421 Excess·] 8,4,-2, -1
0 0000 0000 ruu ""0
I ClOOl 11001 OIlXI 0111
,
(XlIO 0010 0101 0110.1 0011 0011 0110 0101
,
0100 Ol/ XI 0111 0100,
0101 1011 11100 10116 0110 1100 IlXlI 10 10
7 Dill 110 1 1010 1001
,
1000 1110 lUll 1000•
IOUI 1111nco
11J1lOW 0101 0000 0001
Un used 1011 0110 (XXII 0010
bil 1100 0111 (XIIO 0011
combi- 1101 1000 1101 1100
nations 1110 1001 1110 110 1
1111 IOIU 1111 1110
22 Chap ter 1 Digital Systems and Bina ry Numbers
The 242 1 and the e xce ss-J codes are examples of sel f-co mplementing cod es. Such cod es have the property that the 9's co m plement of a decimal number is obtained directly by chang- ing I 's to D's and D's to I 's (i.e., by complementing eac h bit in the pattern ). For example. dec- imal 395 is repre sent ed in the excess-S cod e as 0 II0 1100 1000 . Th e 9 ' s comp lement of 604 is repre sent ed as 1001 00 11 0 111, which is o btained simply by complementing ea ch bit of the cod e (as with the I 's co mplement of binary numbers) .
The excess-S cod e has bee n used in some olde r computers because of its self-complement- ing prope rty. Excess-S is an unweighr ed cod e in which eac h coded combination is obtained fro m the corres po nding binary va lue plus 3. Note that the BCD cod e is no t se lf-complementing.
The 8, 4, -2, -I code is an exa mple of ass igning both positive and nega tive we ights to a decimal code. In this case, the bit combi nation 0 I I0 is interpreted as deci mal 2 and is catcu- latedfrom 8 X O + 4 X I + ( - 2 ) X I + ( - I) x O =2.
Gray Code
The out put dat a of man y physical systems are quantities that are continuous. These data must be conven ed into digital f orm before they are applied
toa digital system. Co ntinuous or analog information is converted into digital form by means of an analog-to-digital converter. It is some- times co nvenient to use the Gray cod e shown in Table l. o to represent digital data that have bee n co nverted fro m analog da ta. The adva ntage of the Gra y code over the straight binary number se quence is that on ly one bit in the cod e group chan ges in go ing fro m one number to the next.
For example, in going from 7 to 8, the Gray cod e changes from 0 1 00 to 1100. Only the first bit c hanges, fro m a
toI ; the other thr ee bits remain the same. By contrast. with binary numbers the change from 7 to 8 will be from 0111 to 1000 , which causes all four bits to change values.
Tabl e 1.6
Gray CodeGr ay Cod e
0000
00010011 001 0 0 110 Oll t 0 101 0100 11 00 1101 ti ll 11 10 1 0 tO tOil 1 001
1000DecImal Equival ent
o
I
2
3
4
5
6
7
8
9
10
II12
13
14
IS
Section1.7 Binary Codes 23
The Graycodeisusedinapplications inwhic hthenorm alseq uenceofbinary numbersmay produceanerroror ambig uity duringthetransitionfro m onenumbe rto the ne xt.Ifbinary numbersare used.a change.forexample. from0111to1000 rna)'prod uceaninter med iateer- roneousnumber1001if thevalueof therightmost bittakeslongerto changethan dotheval- ues of theotherthreebib.TheGraycodeeliminatesthisproblem. sinceonly onebitchanges ils valueduringany transiti on betweentwonumbers.
A typical applicatiunuftheGray codet,therepre sentationof analog data byacontinu- ous cha nge in theangularpositionofashan. Theshaftispa rtitionedintosegme nts. and eachsegmentisassignedanum ber.If adjacent segments aremade to correspo ndwith the Gray-codeseq uence.amb iguityiseliminated betweenthe angleof theshaftandthevalue encodedbythesensor.
ASCIICharacter Code
Man)'applicationsofdigitalcomputersrequirethehand ling nulonlyofnum bers.butalsoof othercharactersor..ymbols.such astheleitersofthealphabet.For instance,aninsurancecom- pany withthousands ofpolicyholderswilluseJcomputer to processilsfiles.Toreprese ntthe name" and otherpertine nt information.itisnece:--"af)'to formulatea binary code forthelet- ters ofthealphabe t.In add ition.thesame binary codeIIlU"trepresentnumeralsandspecial characters (suchas 5).An alp han umeric character set isaset ofclementsthatinclu desthe 10 deci mal digits.the 26lcuI.'rsofrhealphabet. andanumber ofspeci alcharacters.SuchasetCOII- tuin-,belween36and64 clem entsif only capitallettersare included.or belween 64and 12S cleme ntsif both uppercase andlowercaselettersareincluded.In thefirst cuse.we needabi- narycodeofsix bits. and intheseco nd. weneedabinarycod e of sevenbits.
The standardbinarycodeforthe alphanumericchuructc rs istheAmer ican StandardCode forInfo rmation Interchange(ASCII), whichuses seven bits10code 128characte rs.as sho wn in Table1.7.The sevenbilsofthe code are designated byhithrough[,7.withh7themostsig- nifica ntbit.Thelett erA.for example. isrepresented in ASCIIa:,>100000 1(column 100.row 0001).TheASCIIcod ealsocontains 94 graphic characters thatcan beprintedandJ4 non- printingcharactersusedforvariouscontrolfunctions.The graphic cha ractersconsistofthe 26 upperca seletters (Athrou gh Z).the26 low ercaseleit ers(a throug h
n.
the10 numer als(0 through9).and32 "ped a lprintable characters,sucha"C'k,".andS.TheJotco ntrolcharactersarc designated inthe ASCIItablewithabbreviatednames. They arelistedagainbelowthetable withtheir functional names.The controlcharactersareused for routingdataandarrangingtheprimedtext into aprescribed format. Therearethreetypesof controlcharacters: formaleffecto rs.informationscparmors.andcommunication- controlchar- actcrs.Formateffectors arccharactersthat controlthe layout ofprinting.Theyincl ude thefa- miliar word processorandtypewriter controlssuchasbackspace(BSI. horbomalrabuhnion (HTl. andcarriage return(CR).Informationseparators lire used10 sepcrurethedataintodivi- sionssuch as paragraphsand pages.TIleyincludecharacte rssuch a...recordseparator(RS) and fileseparator (FS).Thecommunication-controlcharactersare usefulduringthe transmission of textbetweenremoteterminals.Examples ofcommuntcarion-comrolcharac tersareSTX tstanofrexu and ETX(end oftextI.whichare used10 frameatextmessagetransmitted through telephon e wires.
24 Chapter 1 Digital Syste ms a nd B inary Num bers
Table 1.7
American Standard Code for Information Interchange (ASCII)
b ,b,b s
b
4bJbzb , 000 001 010 011 100 101 110 111
OOOJ
l\"ULOLE SP 0
" P P
(0),
SOH DC. 1 A Q •
q0010
STX DC2 1 B R b r
0011
ETX DC3 • 3 C S c ,
0100
EDT DC. S , 0 T
d0101
El'Q
~AK.. , E U ,
u0110
A CK
SYN &6 F V f
v0111
BEL ETB 7 a w ,
w1(0)
BS
CA:-.i (s H X b ,
1001
HT E M
)9 I
Y,
lOW
L F S U B • J Z j z
1011
VT E SC + K
[ k{
1100
FF F S < L \ • I
110 1 CR as • M 1
m}
1110 SO R S > N
A n1111
$IUS I ? 0
0DEL
Control c:ha raders
/,\ UL
~ullO LE
Data-linkescapeSOH
SianofheadingDCI
Device comrol ISTX Stan of lell DCl Device comrot
2ETX Endoflexl
DC3
Device control3
EDT
Endof tran<;,mi!>sioo DC. Device
comrol4 E"\Q Enquiry :'\AK l'\egative acknowledgeACK Ackno...led ge SYN
S)nchronousidleBEL
RdlETB
End-o(-lran ~ mi ssionblockBS
BackspaceCAS Cancd
HT
HorizontaltabE M End
ofmediumL F
Linefeed SUB Subsumte
VT
Ve rticaltabESC Eo;cape
FF Fonn feed F S f- i le separator
C R Carriage return as Group separator
SO Shift O UI R S Record separator
$I
Shift in US
Unitseparato rSP Space DEL
Dele teASCII is a seven-bit code. but most computers manipulate an eight-bit quanti ty as a single
unit called a byte, Th erefore. ASC II ch aracters most often are stored one per byte. Th e extra
bit is sometimes used for o ther purposes. depending on the application. For example . some
printers recognize eight-bit ASCII characters with the mo st significant bit set to O . An additional
Section 1.8 Binary Sto rageand Registers 2S 128eight-bitcharacters with themost significant bit setto Iare used forothe rsymbols,such as theGreekalphabet or italic typefont.
Error-DetectingCode
Todetect errorsin datacommunicationand processing.aneighthbitis sometimes addedtothe ASCIIcharactertoindicateitsparity.ApI/drybitisanextra bitincludedwithamessagetomake thetotalnumber oflseitherevenorodd.Conside rthefollowingIWOcharactersandtheir even andodd purity:
ASCIIA = 100000 1 ASCII T = 1010100
Witheven par ity 0100000 1
11010 100
Withoddparit y 11000001 01010 100
Ineachcase,weinsert anextrabitintheleft mostpositionof thecodetoprod uce aneven numberoflsinthecharacterforeven parityoranodd num ber oflsin the characterfor odd pari ty.In general,oneorthe other parity isadopted .witheven parity beingmore commo n.
Theparitybit ishelpfulin detectingerror sduringthetransmissionofinformation fromone locutiontoanother.Thisfunction ishandled bygenerating anevenparity bitat the sendingend foreachcharac ter.The eight-bitcharactersthatincludeparitybitsare transmittedtotheir des- tinaticn.The parityofeachcharacte r isthencheckedattherecei ving end.Iftheparityofthe received characterisno t even.then atlea..tonebithas changedvalue duringthe transmission.
Thismeth oddetect s one,three.or anyoddcombinationoferrorsineachcharacterthatistrans- mitted.Anevencombinationoferrors.however.goesundetected. andaddi tionalerror detec- tion codesmayhe neede dtotake careof thatpossibility.
What isduneafteran error isdetecteddepends ontheparticularapplicatio n.Onepossi- bility isto reques trermnsmisslonoftheme ssage on the assumptio nthatthe errorwas ra n- domandwillnot occur again.Thus.if thereceiverdetects aparit y error.itsendsbackthe ASCIINAK(negativeacknowledg e)control characterco nsisting ofaneven-parityeight bits100 10101. Ifno error isdetectedthereceive r sendsbackanACK(acknow ledge )COII-
trolcharacter. namely.00000110.The send ingendwillrespondto an NAK bytransmitting themessageagainuntilthecorrect parityisrecei ved.If.after anumbe r ofatte mpts.the transmissionis stillinerror.a message canhesentto the operatortocheckformalfunctions inthetransmissionpath.
1. 8 81NARY STORAGE AND REG ISTERS
The binaryinformation inadigital co mputermusthaveaphysicalexistenceinsome medi um forstoringindividualbits.Ahillarycelli..adevicethat possessestwo stablestates andis ca- pableofstoringonebit(0or I)ofinformation.Theinputtothe cellreceivesexcitatio nsig·
nal.. thatsetitto oneofthetwostates.Theoutputofthe cellisa physi calquantitythai distinguishesbetweenthetwo states. Theinformationstoredina cellisIwhen thecellisin one stable..tate and () whenthe cellis intheotherstablestate.
26 Chapter 1 Digital Systems and Binary Numbers
Registers
A register is a group o f binary cells. A register with n cells can store any d iscrete quantity of information that contains n bits. The stale of a register is an n-tuple of l 's and O 's. with each bit designating the state of one cell in the register. The content ofa register is a function of the interpretation gi ven to the information stored in it. Consider. for examp le. a 16-bit register with the following binary content:
II ()()()() 1111 ()() 1()()1
A register with 16 cells can be in o ne of 2
16possible stales. If one assumes thai the content of the register represents a binary integer. then the register ca n store any bi nary number from
o to 2
16 -I. For the particular example shown. the co ntent of the register is the bi nary equiv- alent of the dec imal number 50. 121. If one assumes instead that the register stores alphanu- meric characters of an eight-bit code. then the co ntent of the register is any two meaningful character s. For the ASCII code with an eve n pari ty placed in the eighth most significant bit position. the register contains the two characters C (the leftmost eight bits) and I (the right- most eight bits). If. however. one interprets the content of the register to be four decimal dig- its represented by a four-bit code. then the content of the register is a four-digi t decimal number. In th e excess-S code. the register holds the decimal number 9 .096. The content of the register is meaning less in BCD . because the bit combination 11 00 is not assigned to any dec- imal digit. From this example. it is clear that a register can store discrete elements of infor- mation and that the same bit configuration may be interpreted differently for d ifferent types of data.
Register Transfer
Adi gital system is characterized by its registers and the components that perform data pro-
cessing. In digital systems. a register transfer operation is a basic ope ration that co nsists of
a transfer o f binary info rmation from one set of registers into another set o f registers. T he
transfer may be dire ct . from one register to anothe r. or may pass through data-processing
circui ts to perform an operat ion. Figure 1.1 illustrates the transfer of information amo ng reg-
ister s and demon strates pictorially the tran sfer of binary inform ation from a keyboard into
a register in the memory unit. The input unit is ass umed to have a keyboard . a cont rol cir-
cuit. and an inpu t register. Each time a key is struck. the control circui t enters an eq uiva-
lent eight-bit alphanumeric character code into the inpu t register. We shall assume that the
code used is the ASCII code with an odd-parit y bit. The informatio n fro m the input regis-
ter is transferred into the eight least significant cells of a processor register. After eve ry
transfer, the input register is cleared to ena ble the co ntrol
toinsert a ne w eight-bi t code
when the keyboa rd is struck again . Each eig ht-bit character transferred to the processor
register is preceded by a shift of the previous character to the next eight ce lls on its left. When
a transfe r of four characters is completed. the processor register is full. and its contents are
transferred into a memory register. The content stored in the memory register shown in Fig. 1.1
came from the transfer of the cha racters " J:' " 0:' " H: ' and " N" after the fo ur approp riate
keys were struc k.
Section1.8 Binary Storageand Reg ist e rs 27
InpUI RegiMer::'
" , - ,•or Rcgi<,! ('r
('OSTROl
~:
','
..
,.i'::'::=::±=:-:-c:':"::=~::::c=:'1
AI...,·
Re~C'r
Keyboard
FIGURE 1.1
Tra nsfe r ofInfo rma tion among reglslers
Toproc ess discrete quan titiesofinformatio nin binaryform.a computerrnuvt be pro- vided withdevices thaiho ld thedata10beprocessedand withcircuitelementsthatmanip- ulateindividual bitsofinformalio n.Thedev icemostcommonlyusedfo r holdingdata is a re gister.Binaryvariablesareman ipulatedbymeans of digital log iccircuits.Figure 1.2il- lustrate stheproc ess ofadd ingtwo ID-bitbinarynumbers.Thememo ryunit whichnor- mally con..ists ofmillions ofregisters.isshownwithonlythree ofit.. register s,The panof the proces ..or unitsho wncon..i..l,orrnreercgi ..lt.:r s-RI .R1.and R3- togclhcrwith digilal logic circuitsthatmanipul atethehitsofRIandR2andtran ..ferinto RJabinary number cq calto the ir arithmetic"UIlI.Mem ory regi..tcrsstore informationanti arcincapableofpro- cessingthetwooperands.However.theinforma tionstore dinmem ory canbetransferred to processor register s.andthe resultsobtain edin proc e....orregisterscanhetransferredbackiruo a mem ory registerfor storageuntilneed ed again.Thediagram shew..the con tentsofIWO
operands tran sfer redfromtwomemor yregistersintoRIand R2.Thedigitallogiccircuits producethesum,whichistransferredtoregisterR3.Theconte ntsofRJcannowbetrans- (erredback10one ofthemem o ry registers.
ThelaS!two examplesdem onstrated the information-flowcapabilitiesof a digitalsyste m in asimple manner;Theregisters of thesystemaretheba..icelementsforMoringand holding.
thebinary informa tio n.Digitallo giccircuitsprocess the binary inform ation stored in the
28 Chapter 1 Digital S ystem s and Binary Numbers
~1EMORY
uxrr
10000000000 Sum
Operand I
00111000011
Opereed2
00010000101
OOO IOOOO IOIRI
1
Digitallogic
circuitsfor
-...j0 1OO10 001 11R3bin ary addition
1
0011lOOOO1lR2
PROCESSOR !.NIT
-
F IGURE 1.2
Example of binary inform atio n proce ssing
registers. Digital logic c ircuits andregisters are covered in Chapters 2 throu gh 6. Tbe memory unit is e xplained in Chapter 7. The description of register operations at the register tran sfer level and the design o f digit