11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

54 Part I: Introduction to C++ ProgrammingThe decimal number systemThe numbers we’ve been familiar with from the time we could first counton our fingers are known as decimal numbers because they’re based on thenumber 10. (Coincidence? I don’t think so . . .) In general, the programmerexpresses C++ variables as decimal numbers. Thus you could specify thevalue of var as (say) 123 — but consider the implications.A number such as 123 refers to 1 * 100 + 2 * 10 + 3 * 1. Each of thesebase numbers — 100, 10, and 1 — are powers of 10.123 = 1 * 100 + 2 * 10 + 3 * 1Expressed in a slightly different (but equivalent) way, 123 looks like this:123 = 1 * 10 2 + 2 * 10 1 + 3 * 10 0Remember that any number to the zero power is 1.Other number systemsWell, okay, using 10 as the basis (or base) of our counting system probablystems from those 10 human fingers, the original counting tools. An alternativebase for a counting system could just as easily have been 20 (maybe theinventor of base 10 had shoes on at the time).If our numbering scheme had been invented by dogs, it might well be based on8 (one digit of each paw is out of sight on the back part of the leg). Mathematically,such an octal system would have worked just as well:123 10 = 1 * 8 2 + 7 * 8 1 + 3 * 8 0 = 173 8The small 10 and 8 here refer to the numbering system, 10 for decimal(base 10) and 8 for octal (base 8). A counting system may use any positivebase.The binary number systemComputers have essentially two fingers. (Maybe that’s why computers are sostupid: without an opposing thumb, they can’t grasp anything. And then again,maybe not.) Computers prefer counting using base 2. The number 123 10 wouldbe expressed this way:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!