Introduction to Algorithms
64
When you are looking at these numbers, you do not know if they are in base 2 or base 10. For
example,
the first number,
100
, could be either 100 in base 10 or 4 in base 2.
There are several notations you can use to show a number is base 2. For example,
computer scientists
often put a
b
before a number to show the number is in base 2. Here are other
ways to indicate that a
number is in base 2:
100b
1000
2
%100
0b100
A
place value is the numerical value a digit has because of its position in a number. For example, a
four- digit number has place values that represent thousands, hundreds, tens, and ones. For example, the
number 1,452
is one thousand, plus four hundreds,
plus five tens, plus two ones (Figure 6.1).
In the decimal system, each place value is a power of 10. The rightmost place value is 10 to the
zero power, which is 1. The next place value is 10
to the first power, which is 10. The next place value
is 10 to the second power (10 × 10), which is 100. The next place value is 10
to the third power
(10 × 10 × 10), which is 1000 (Figure 6.2).
You can express the number 1,452 as an equation using its place values:
(1 * 10 ** 3) + (4 * 10 ** 2) + (5 * 10 ** 1) + (2 * 10 ** 0) = 1452
Or visualize it as follows:
1 * 10 ** 3 = 1 * 1000 = 1000 +
4 * 10 ** 2 = 4 * 100 = 400 +
5 * 10 ** 1 = 5 * 10 = 50 +
Thousands Hundreds
Tens
Ones
Do'stlaringiz bilan baham: