We use number bases every day without realizing it. When we think about numbers in everyday life, we are almost always thinking of decimal numbers, or numbers in base 10, where each digit of a number can be one of ten values. People have ten fingers and ten toes (most of the time), so it seems natural to base a number system on ten. But, we are not required to use ten as a base. For example, in the movie Avatar, the Na’vi inhabitants have eight fingers and base their number system on eight because of that. Back on Earth, we see other bases use commonly in computing systems, such as binary (base 2) and hexadecimal (base 16).
When we wish to discuss non-ten bases, we use a leading notation like this: 0b1100111101 (binary for decimal 829). In common computer languages, we see, and we will use, this notation for the following bases:
- Binary (Base 2): leading 0b
- Octal (Base 8): leading 0o
- Decimal (Base 10): leading nothing (we use it all the time!)
- Hexadecimal (Base 16): leading 0x
The position of a number indicates its underlying value. We start at value zero and increase by one each time we move to the left. This statement is evident in the example.
For example, with 120, we have
Let’s revisit the pattern from right to left: ones, tens, hundreds, thousands. If we multiply it out, we go from left to right again: hundreds, tens, ones. Here are the exponents from left to right: 2, 1, 0.
In order to convert numbers in non-decimal bases to their decimal counterpart that we intuitively understand, we rely on the base number and the position of each digit. Starting from right to left, we compute the base conversion of that individual digit and add the decimal equivalent of that digit’s position.
Let’s try that with binary! Let’s look at
100 in binary, or
0b100. Remember, we’re working in base
2, so our equation will now be
This leaves us with
4 + 0 + 0, or
100 in binary is equal to
4 in base 10!
Let’s say we have a number in base 10 with 5 digits, like
If we were to break this number into its components, what would be the value of the exponent for the digit
Assign the value to
checkpoint_1 in the code editor.
For any number, regardless of what base system we’re working in, what is the value of the exponent for the first digit (rightmost column)?
Assign this value to
checkpoint_2 in the code editor.