Skip to main content

Discrete Mathematics for Computing (Draft)

Section 1.3 Converting from Base-10 to Non-Standard Bases

In the previous section, we considered that representation of numbers using bases other than the base-10 (decimal) system is possible, and sometimes necessary. In that section you considered the true meaning of place-value and built on your intuitive understanding to identify a scheme for converting an integer, written in any non-standard base, into its decimal- equivalent.
In this section, we’ll work in the opposite direction. Say we have a decimal represresentation of a value. How do we identify or construct its base-\(b\) equivalent?

Subsection 1.3.1 Developing a Strategy

THIS SECTION WILL NEED LOTS OF EDITING -- just getting a "working version" up for now.
In order to convert a value whose decimal representation is \(n\) into its corresponding base-\(b\) equivalent, we need to first identify the number of whole copies of \(b\) which divide evenly into \(n\text{.}\) The left over amount (you’ve likely called this the remainder when discussing division in your previous math courses) will be the singles digit in the base-\(b\) representation of \(n\text{.}\)
Let’s consider an example, which we’ll parse throughout this discussion. Consider the decimal value \(n = 113\text{,}\) for which we’ll try to discover its base-\(3\) equivalent. The paragraph above suggests that we should start by identifying the number of "whole copies" of \(3\) which divide evenly into \(113\text{.}\) Notice that \(3\cdot 37 = 111\text{,}\) so there are \(37\) "whole" copies of \(3\) within the decimal value \(113\text{,}\) with a remainder of \(2\text{.}\) That is, \(113 = 3\cdot \left(37\right) + 2\text{,}\) and \(2\) will occupy the singles-digit in the base-\(3\) representation of \(113\text{.}\)
How can we identify the next digit to the left in the base-\(3\) representation of \(113\text{?}\) That digit will be the remainder after considering the number of whole copies of \(3^2\) within the decimal value \(113\text{,}\) after accounting for the singles digit. That is, the digit occupying the second place-value will be the remainder after considering the number of whole copies of \(9\) which divide evenly into \(\left( 113 - 2\right)\text{.}\) More simply, we could consider the remainder after \(3\) is divided into \(37\) -- the quotient from the previous step. From here, we note that \(37 = 3\cdot \left(12\right) + 1\text{,}\) and so the digit occupying the second position will be \(1\text{.}\)
Identifying the digit occupying the remaining positions is similar. The next digit will be the remainder, when dividing \(3\) into the quotient from the previous step (here, that value was \(12\)). Since \(12 = 3\cdot \left(4\right) + 0\text{,}\) the digit occupying the third position from the right is \(0\text{.}\) Similarly, the digit occupying the next position is the remainder after \(3\) is divided into \(4\) (again, using the previous quotient). Since \(4 = 3\cdot\left(1\right) + 1\text{,}\) the digit occupying that fourth position is \(1\text{.}\) Finally, the leftmost digit will be the remainder when this quotient (\(1\)) is divided by the desired base (here, \(3\)). So we have \(1 = 3\cdot \left(0\right) + 1\text{,}\) and the leftmost digit is \(1\text{.}\) To summarize, we’ve discovered that \(\left(113\right)_{10} = \left(11012\right)_{3}\text{.}\)
Let’s describe the process above before summarizing with a more concise version of the procedure. If we wish to find the base-\(b\) equivalent representation of the decimal integer \(n\text{,}\) we write
\begin{equation*} n = b\cdot q_{0} + r_{0}, \text{ where } 0 \leq r_{0} \lt b \end{equation*}
Next, we rewrite \(q_{0}\) in the same fashion.
\begin{equation*} q_{0} = b\cdot q_{1} + r_{1}, \text{ where } 0 \leq r_{1} \lt b \end{equation*}
We continue this while the quotients, \(q_{i}\) are non-zero. Once we arrive at a quotient \(q_{k} = 0\text{,}\) the process terminates and we use the remainders to write the base-\(b\) representation \(\left(r_{k}r_{k-1}\cdots r_{1}r_{0}\right)_{b}\) of our original \(n\text{.}\)
We recap the process of constructing the base-\(3\) equivalent of \(\left(113\right)_{10}\) below.
\begin{align*} 113 \amp = 3\cdot 37 + 2\\ 37 \amp = 3\cdot 12 + 1\\ 12 \amp = 3\cdot 4 + 0\\ 4 \amp = 3\cdot 1 + 1\\ 1 \amp = 3\cdot 0 + 1 \end{align*}
At the last line, we arrive at a quotient of \(0\text{,}\) so we terminate the procedure. The base-\(3\) encoding of \(\left(113\right)_{10}\) is given by \(\left(11012\right)_{3}\text{,}\) reading the remainders from the last line back up to the first.

Subsection 1.3.2 Let’s Try It!

Now that we’ve developed a strategy for writing the base-\(b\) equivalent of a given decimal integer, let’s get more comfortable using it. In this section, you’ll have a variety of opportunities to work through our algorithm. You’ll have lots of support through the initial examples, but we’ll provide less and less structure with each successive task.

Checkpoint 1.3.1. Convert to Binary, Part I.

Checkpoint 1.3.2. Convert to Binary, Part II.

Checkpoint 1.3.3. Convert to Binary, Part III.

Checkpoint 1.3.4. Convert to Binary, Part IV.

Now that you’ve converted from decimal to binary a few times, let’s work with some other bases. In the examples that follow, the bases we want to convert to will change but your strategy remains the same.

Checkpoint 1.3.5. Convert to Base-b I.

Checkpoint 1.3.6. Convert to Base-b II.

Checkpoint 1.3.7. Convert to Base-b III.

Subsection 1.3.3 Converting to Hexadecimal

Let’s close out the section with an example showing how to convert a decimal integer into hexadecimal. As reminder, hexadecimal is the base-\(16\) number system. We make use of the characters \(A\) through \(F\) to reprecent the decimal values \(10\) through \(15\) in order to avoid ambiguity in the base-\(16\) value we are writing. Below is a completely worked example, but it is followed by an embedded exercise for you to confirm your understanding.

Example 1.3.8. Converting from Decimal to Hexadecimal (base-16).

Convert \(\left(1133\right)_{10}\) to its equivalent hexadecimal form.
\begin{align*} 1133 \amp = 16\cdot 70 + 13\\ 70 \amp = 16\cdot 4 + 6\\ 4 \amp = 16\cdot 0 + 4 \end{align*}
Remembering that \(\left(13\right)_{10} = \left(D\right)_{16}\text{,}\) we can write the hexadecimal representation of \(\left(1133\right)_{10}\) as \(\left(46D\right)_{16}\text{.}\)

Checkpoint 1.3.9. Convert to Hexadecimal.

Subsection 1.3.4 Conclusion

In this section, we’ve learned the mechanics of converting a decimal number into its base-\(b\) equivalent for a variety of bases. You got practice implementing the conversion algorithm, and even worked in bases higher than \(10\) -- where we needed to introduce the use of symbols to represent large digits. In the next section, we’ll explore the most common non-standard base systems in a bit more detail. We’ll also highlight the connections between them.