31/ 6c0 010 010 0Es PSa3n>S >19 2 .16 8 .14 7.6by4xt" >19 2 .16 8 .14 7 padding="0"><">" name="description"/>
Tải bản đầy đủ - 0 (trang)
Appendix A.  Tutorial: Working with Binary and Hex

# Appendix A.  Tutorial: Working with Binary and Hex

Tải bản đầy đủ - 0trang

100=1

101=1x10=10

102=10x10=100

103=100x10=1000

104=1000x10=10,000

So,thefirstfiveplacevaluesofthebase10numberingsystem

are

10,0001000100101

meanstherearefivequantitiesof10,000,sevenquantitiesof

1000,twoquantitiesof100,fivequantitiesof10,andeight

quantitiesof1.Thatis,

5x10,000=50,000

7x1000=7000

2x100=200

5x10=50

8x1=8

7000+200+50+8=57,258.

Allofusaresoacquaintedwithworkinginbase10thatwe

seldomthinkofbreakinganumberdownintoitsplacevalues.

However,thistechniqueisessentialtodeciphernumbersin

otherbases.

WorkingwithBinaryNumbers

Computersare,atthemostfundamentallevel,simplya

collectionofelectricalswitches.Numbersandcharactersare

representedbythepositionsoftheseswitches.Becausea

switchhasonlytwopositions,onoroff,itusesabinary,orbase

2,numberingsystem.(Therootbimeanstwo.)Abase2

systemhasonlytwodigits:0and1.

Computersusuallygroupthesedigitsintoeightplacevalues,

knownasabyteoranoctet.Theeightplacevaluesare

2726252423222120

Theplacevaluesarecalculatedasfollows:

20=1

21=1x2=2

22=2x2=4

23=4x2=8

24=8x2=16

25=16x2=32

26=32x2=64

27=64x2=128

So,theplacevaluesofabinaryoctetare

1286432168421

1x128=128

0x64=0

0x32=0

1x16=16

0x8=0

1x4=4

1x2=2

1x1=1

or128+16+4+2+1=151

Workinginbinaryiseasybecauseforeveryplacevaluethereis

eitheronequantityofthatvalueornoneofthatvalue.For

anotherexample,11101001=128+64+32+8+1=233.

placevalues,convertingfromdecimaltobinaryisamatterof

subtractingplacevalues.Toconvertthedecimalnumber178to

binary,forinstance,beginbysubtractingthehighestbase2

placevaluepossiblefromthenumber:

1. 178isgreaterthan128,soweknowthereisa1atthat

placevalue:178128=50.

2. 50islessthan64,sothereisa0atthatplacevalue.

3. 50isgreaterthan32,sothereisa1atthatplacevalue:50

32=18.

4. 18isgreaterthan16,sothereisa1atthatplacevalue:18

16=2.

5. 2islessthan8,sothereisa0atthatplacevalue.

6. 2islessthan4,sothereisa0atthatplacevalue.

7. 2isequalto2,sothereisa1atthatplacevalue:22=0.

8. 0islessthan1,sothereisa0atthatplacevalue.

Puttingtheresultsofallthesestepstogether,178is10110010

inbinary.

1. 110islessthan128,sothereisa0atthatplacevalue.

2. 110isgreaterthan64,sothereisa1atthatplacevalue:

11064=46.

3. 46isgreaterthan32,sothereisa1atthatplacevalue:46

32=14.

4. 14islessthan16,sothereisa0atthatplacevalue.

5. 14isgreaterthan8,sothereisa1atthatplacevalue:14

8=6.

6. 6isgreaterthan4,sothereisa1atthatplacevalue:64

=2.

7. Thereisa1atthe2placevalue:22=0.

8. 0islessthan1,sothereisa0atthatplacevalue.

Therefore,110is01101110inbinary.

Writingoutbinaryoctetsisn'tmuchfun.Forpeoplewhomust

workwithsuchnumbersfrequently,abriefernotationis

welcome.Onepossiblenotationistohaveasinglecharacterfor

everypossibleoctet;however,thereare28=256different

combinationsofeightbits,soasingle-characterrepresentation

ofalloctetswouldrequire256digits,orabase256numbering

system.

Lifeismucheasierifanoctetisviewedastwogroupsoffour

bits.Forinstance,11010011canbeviewedas1101and0011.

Thereare24=16possiblecombinationsoffourbits,sowitha

representedwithtwodigits.(Theroothexmeanssix,anddeci

decimalandbinaryequivalents.

TableA-1.Hex,decimal,andbinaryequivalents.

Hex

Decimal

Binary

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

A

10

1010

B

11

1011

C

12

1100

D

13

1101

E

14

1110

F

15

1111

Becausethefirst10charactersofthedecimalandthe

precedeahexnumberwitha0x,orfollowitwithanh,to

number25wouldbewrittenas0x25oras25h.Thisbookuses

the0xconvention.

Afterworkingwithbinaryforonlyashortwhile,itiseasyto

doneinthreesteps:

1. Dividetheoctetintotwo4-bitbinarynumbers.

2. Converteach4-bitnumbertodecimal.

3. Writeeachdecimalnumberinitshexequivalent.

Forexample,toconvert11010011tohex,

1. 11010011becomes1101and0011.

2. 1101=8+4+1=13,and0011=2+1=3.

3. 13=0xD,and3=0x3.

Therefore,11010011inhexis0xD3.

Convertingfromhextobinaryisasimplematterofworkingthe

threestepsbackward.Forexample,toconvert0x7Btobinary,

1. 0x7=7,and0xB=11.

2. 7=0111,and11=1011.

3. Puttingthe4-bitnumberstogether,0x7B=01111011,

whichisdecimal123.

AppendixB.Tutorial:AccessLists

Accesslistsareprobablymisnamedthesedays.Asthename

implies,theoriginalintentionofanaccesslistwastopermitor

denyaccessofpacketsinto,outof,orthrougharouter.Access

listshavebecomepowerfultoolsforcontrollingthebehaviorof

packetsandframes.Theirusefallsintothreecategories(see

FigureB-1):

Securityfiltersprotecttheintegrityoftherouterandthe

networkstowhichtheyarepassingtraffic.Typically,

securityfilterspermitthepassageofafew,well-understood

packetsanddenythepassageofeverythingelse.

Trafficfilterspreventunnecessarypacketsfrompassing

muchlikesecurityfilters,butthelogicisgenerallyinverse:

Trafficfiltersdenythepassageofafewunwantedpackets

andpermiteverythingelse.

Packetidentificationisrequiredformanytoolsavailableon

Ciscorouters,suchasdialerlists,routefilters,routemaps,

andqueuinglists.Thetoolsmustbeabletoidentifycertain

theseandothertoolstoprovidethispacketidentification

function.

FigureB-1.Accesslistsareusedassecurity

filters,astrafficfilters,andforpacket

identification.

### Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix A.  Tutorial: Working with Binary and Hex

Tải bản đầy đủ ngay(0 tr)

×