Upload
dee-can
View
219
Download
0
Embed Size (px)
Citation preview
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
1/19
Functionspackageupcomputationwhendoweusethem?Allthetime.
Writesomesimplecodetoachieveagoal
1/31/11 2010 Larry Snyder, CSE 1
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
2/19
Toputtherectangleindifferentplaces,weparameterizetheposition,thatis,use
inputtothefunctiontoplacetherectangle
1/31/11 2010 Larry Snyder, CSE 2
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
3/19
Nowwequitthinkingofdrawingarectangle,butnowthinkofplacinga50x50rectangle
1/31/11 2010 Larry Snyder, CSE 3
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
4/19
Returntolastlecturefortwoslidesonthetopicofparameters
1/31/11 2010 Larry Snyder, CSE 4
Parameters: Customize each function call
to a specific situation they are the input tothe function
Parameters are the names of the inputvalues used inside of the procedure body
Arguments are the values from outside tobe used for each of the parameters
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
5/19
NoticethatiftheDEFINITIONhasnparameters,theCALLneedsnarguments
Theparametersandargumentscorrespond
1/31/11 2010 Larry Snyder, CSE 5
Inside of the function, the
parameter, e.g. xbase, is
declared and initialized to thecorresponding argument, e.g. 80.
Then, the definition uses it, e.g.
rect(80, 40+10, 20, 40)
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
6/19
Parametersareautomaticallydeclared(andinitialized)onacall,andremaininexistence
aslongasthefunctionremainsunfinished Whenthefunctionends,theparameters
vanish,onlytoberecreatedonthenextcall Itiswisetochooseparameternames,e.g.
xbasethataremeaningfultoyou
Ichosexbaseastheorientationpointofthefigureinthexdirection NoticethatIusedthatnamealot,andthemeaningtomeremainedthesame
1/31/11 2010 Larry Snyder, CSE 6
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
7/19
Wesaid(itwasthe2nddayofclass)thatafunctiondefinitionhas3parts:name,
params,body
Nameiscritical:itnamestheconceptcreatedbythefunction
Parametersarecritical:theycustomizeafunctiontomanycases
Bodyiscritical:itdefineshowthefunctionworks Functionuses(calls)have2parts:name,args Nameiscritical:sayswhatconceptyouwilluse Argumentsarecritical:sayshowthiscasehandled
1/31/11 2010 Larry Snyder, CSE 7
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
8/19
LawrenceSnyderUniversityofWashington,Seattle
Lawrence Snyder 2004
Bits are IT
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
9/19
Analogueinformationdirectlyappliesphysicalphenomena,e.g.vinylrecords
1/31/11 2010 Larry Snyder, CSE 9
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
10/19
Samplingthewave
1/31/11 2010 Larry Snyder, CSE 10
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
11/19
1/31/11 2010 Larry Snyder, CSE 11
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
12/19
Analogisneededfortherealworld
Digitalisbestforinformationworld
Canbemodified,enhanced,remixed,etc Shared,storedpermanently,reproduced,
1/31/11 2010 Larry Snyder, CSE 12
Device DriverMemory A/D Converter
Device DriverMemory D/A Converter
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
13/19
Factsaboutphysicalrepresentation: Informationisrepresentedbythepresenceorabsenceofaphysicalphenomenon(PandA)
Holepunchedinacard;nohole[Hollerith] Dogbarksinthenight;nobarkinginthenight[Holmes] Wireiselectricallycharged;wireisneutral ETC
Abstractallthesecaseswith0and1;itunifiesthemsowedonthavetoconsiderthedetails
1/31/11 2010 Larry Snyder, CSE 13
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
14/19
Binaryissufficientfornumberrepresentation(place/value)andarithmetic
Thenumberbaseis2,insteadof10 Binaryadditionisjustlikeadditioninanyotherbaseexceptithasfewercasesbetterforcircuits
Allarithmeticandstandardcalculationshavebinaryequivalents
Weconclude:bitsworkforquantities
1/31/11 2010 Larry Snyder, CSE 14
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
15/19
Bytesillustratethatbitscanbegroupedinsequencetogenerateuniquepatterns
2bitsinsequence,22=4patterns:00,01,10,11 4bitsinsequence,24=8patterns:0000,0001, 8bitsinsequence,28=256patterns:00000000,
ASCIIgroups8bitsinsequence
Theyseemtobeassignedintelligently,
buttheyrejustpatterns
1/31/11 2010 Larry Snyder, CSE 15
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
16/19
ComparebinaryarithmetictoASCII Binaryencodesthepositionstomakeusingtheinformation(numbers)easy,likeforaddition
ASCIIassignssomepatterntoeachletter
Givenanyfinitesetofthingscolors,computeraddresses,Englishwords,etc.
WemightfigureoutasmartwaytorepresentthemasbitscolorscangivelightintensityofRGB
Wecanjustassignpatterns,andmanipulatethembypatternmatchingredcanbe00000001,darkred00000010,etc.
1/31/11 2010 Larry Snyder, CSE 16
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
17/19
Whatdoesthisrepresent:00000000111100010000100000100000?
Youdontknowuntilyouhowitwasencoded Asabinarynumber:15,796,256 Asacolor,RGB(241,8,32) Asacomputerinstruction:Add1,7,17 AsASCII:nubs IPAddress:0.241.8.32 Hexadecimalnumber:00F10820 toinfinityandbeyond
1/31/11 2010 Larry Snyder, CSE 17
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
18/19
Thisistheprinciple:
1/31/11 2010 Larry Snyder, CSE 18
Bias-free Universal Medium Principle:
Bits can represent all discrete information;
bits have no inherent meaning
8/6/2019 Cse120wi11lec12[1]FuncParaRev Bits r It Encoding
19/19
Analoginformationmustbemadediscrete(digitized)beforeitcanbeprocessedby
computersthisisdonebyA/Dconverter
Thereverseprocessletsushearit:D/A Bitsaresufficienttoencodealldiscrete
information Bitshavenoinherentmeaning,sotheycan
beusedforanything
1/31/11 2010 Larry Snyder, CSE 19