ebook img

Numbers and computers PDF

237 Pages·2015·1.631 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Numbers and computers

Ronald T. Kneusel Numbers and Computers Numbers and Computers Ronald T. Kneusel Numbers and Computers 123 RonaldT.Kneusel Broomfield,CO,USA ISBN978-3-319-17259-0 ISBN978-3-319-17260-6 (eBook) DOI10.1007/978-3-319-17260-6 LibraryofCongressControlNumber:2015935728 SpringerChamHeidelbergNewYorkDordrechtLondon ©SpringerInternationalPublishingSwitzerland2015 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Thepublisher,theauthorsandtheeditorsaresafetoassumethattheadviceandinformationinthisbook arebelievedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsor theeditorsgiveawarranty,expressorimplied,withrespecttothematerialcontainedhereinorforany errorsoromissionsthatmayhavebeenmade. Printedonacid-freepaper SpringerInternationalPublishingAGSwitzerlandispartofSpringerScience+BusinessMedia(www. springer.com) Tomyparents,JanetandTom,forfostering myloveofscience. Preface This is a book about numbers and how those numbers are represented in and operatedonbycomputers. Of course, numbers are fundamental to how computers operate because, in the end,everythingacomputerworkswithisanumber.Itiscrucialthatpeoplewhode- velopcodeunderstandthisareabecausethenumericaloperationsallowedbycom- putersandthelimitationsofthoseoperations,especiallyintheareaoffloatingpoint math, affect virtually everything people try to do with computers. This book aims tohelpbyexploring,insufficient,butnotoverwhelming,detail,justwhatitisthat computersdowithnumbers. WhoShouldReadThisBook Thisbookisforanyonewhodevelopssoftwareincludingsoftwareengineers,scien- tists,computersciencestudents,andengineeringstudentsandanyonewhoprograms forfun. Ifyouareasoftwareengineer,youshouldalreadybefamiliarwithmanyofthe topics in this book, especially if you have been in the field for any length of time. Still,Iurgeyoutopresson,forperhapsyouwillfindagemortwowhicharenew toyou. Ifyouareoldenough,youwillrememberthedaysofFortranandmainframes.If so,likethesoftwareengineersabove,youareprobablyalsofamiliarwiththebasics ofhowcomputersrepresentandoperateonnumbers,but,alsolikethesoftwareen- gineersabove,youwilllikelyfindagemortwoofyourown.Scientistsinparticular shouldbeawareofthelimitationsandpitfallsassociatedwithusingfloating point numberssincefewthingsinsciencearerestrictedtointegers. Students need this book because it is essential to know what the computer is doing under the hood. After all, if you are going to make a career of computers, whywouldyounotwanttoknowhowthemachineworks? vii viii Preface HowtoUseThisBook Thisbookconsistsoftwomainparts.Thefirstdealswithstandardrepresentationsof integersandfloatingpointnumbers,whiletheseconddetailsseveralothernumber representationswhicharenicetoknowaboutandhandyfromtimetotime.Either partisagoodplacetostart,thoughitisprobablybestifthepartsthemselvesareread fromstarttoend.Later,afterthebookhasbeenread,youcanuseitasareference. Thereareexercisesattheendofeachchapter.Mostoftheseareofthestraightfor- wardpencilandpaperkind,justtotestyourunderstanding,whileothersaresmall programming projects meant to increase your familiarity with the material. Exer- cises that are (subjectively) more difficult will be marked with either one or two stars(*or**)toindicatethelevelofdifficulty. Example code is in C and/or Python version 2.7, though earlier 2.x versions should work just as well. Intimate knowledge of these programming languages is notnecessaryinordertounderstandtheconceptsbeingdiscussed.Ifsomethingis not easy to see in the code, it will be described in the text. Why C? Because C is alow-levellanguage,closetothenumberswewillbeworkingwithandbecauseC isthegrandfather ofmostcommon programming languages incurrentuseinclud- ing Python. In general, code will be offset from text and in a monospace font. For readers not familiar with C and/or Python, there are a plethora of tutorials on theWebandreferencebooksbythebookcase.Twoexamples,gearedtowardpeo- ple less familiar with programming, are Beginning C by Ivor Horton and Python Programming Fundamentals by Kent Lee. Both of these texts are available from Springerinprintore-bookformat. Attheendofeachchapterarereferencesforthematerialpresentedinthechapter. Muchcanbelearnedbylookingatthesereferences.Almostbyinstinctwetendto ignore sections like this as we are now programmed to ignore advertisements on webpages.Inthisformercase,resisttemptation;inthelattercase,keepcalmand carryon. Acknowledgments This book was not written in a vacuum. Here I want to acknowledge those who helped make it a reality. First, the reviewers, who gave of their time and talent to givemeextremelyvaluablecommentsandfriendlycriticism:RobertKneusel,M.S., JimPendleton,EdScott,Ph.D.,andMichaelGalloy,Ph.D.Gentlemen,thankyou. Second, thank you to Springer, especially my editor, Courtney Clark, for moving ahead with this book. Lastly, and most importantly, thank you to my wife, Maria, and our children: David, Peter, Paul, Monica, Joseph, and Francis. Without your patienceandencouragement,noneofthiswouldhavebeenwritten. Broomfield,USA RonaldT.Kneusel December2014 AM+DG Contents PartI StandardRepresentations 1 NumberSystems ............................................... 3 1.1 RepresentingNumbers ...................................... 3 1.2 TheBigThree(andOneOldGuy) ............................ 8 1.3 ConvertingBetweenNumberBases ........................... 10 1.4 ChapterSummary .......................................... 16 Exercises ...................................................... 16 References..................................................... 16 2 Integers....................................................... 19 2.1 Bits,Nibbles,Bytes,andWords .............................. 19 2.2 UnsignedIntegers .......................................... 21 2.2.1 Representation ...................................... 22 2.2.2 StorageinMemory:Endianness........................ 22 2.3 OperationsonUnsignedIntegers.............................. 25 2.3.1 BitwiseLogicalOperations............................ 25 2.3.2 Testing,Setting,Clearing,andTogglingBits ............. 30 2.3.3 ShiftsandRotates.................................... 33 2.3.4 Comparisons........................................ 37 2.3.5 Arithmetic.......................................... 41 2.3.6 SquareRoots........................................ 52 2.4 WhatAboutNegativeIntegers?............................... 53 2.4.1 Sign-Magnitude ..................................... 54 2.4.2 One’sComplement................................... 54 2.4.3 Two’sComplement .................................. 55 2.5 OperationsonSignedIntegers................................ 56 2.5.1 Comparison......................................... 56 2.5.2 Arithmetic.......................................... 57 2.6 Binary-CodedDecimal...................................... 66 2.6.1 Introduction......................................... 66 ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.