6. Number Bases

This chapter was last updated on April 1, 2025.

It’s likely that you learned how to represent positive integers using the base-ten place-value system when you were young. This system uses ten symbols, the Hindu-Arabic numerals ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, and ‘9’, to represent any natural number.

In the base-ten place-value system that uses decimal notation, each natural number is represented by a numeral which is a string of one or more of the ten Hindu-Arabic digits. However, in some computer science contexts, it is more useful to represent natural numbers in a place-value system that uses a different number base such as binary (base-two), octal (base-eight), or hexadecimal (base-sixteen). Using or thinking about numbers represented by numerals in these other systems can help you develop more efficient algorithms and recognize when certain numerals can be interpreted as encodings of multiple pieces of information.

In this chapter, you will learn how to represent natural numbers using place-value systems with bases other than ten.

Key terms and concepts covered in this chapter:

  • Number bases

    • binary

    • hexadecimal

    • octal

    • decimal

6.1. Numbers, Numerals, and Digits

In everyday life, it is common to treat numbers and numerals as if they are the same. However, it is important in this chapter to distinguish these concepts.

  • A number is an abstract idea or mental concept of a count, a measure, a rank in an ordering, etc..

  • A numeral is a word, phrase, symbol, or string of symbols that is used to represent a number.

  • A digit is a single symbol that represents a number. A digit is a numeral, but multiple digits can be combined to create other numerals. For example, each of the ten Hindu-Arabic numerals is a digit that represents a natural number that is less than ten, and multiple Hindu-Arabic numerals can be combined to create numerals that represent numbers that are greater than or equal to ten.
    NOTE: The word "digit" comes from the Latin word digitus which means "finger" or "toe."

Example 1 - Numerals, Numbers, and Digits

Consider the following words:

  • "five",

  • "cinco",

  • "خمسة" ("khamsa"),

  • "पाँच" ("paanch"),

  • "五" ("wǔ").

These words, taken from different languages, are examples of numerals, words that represent a number. In fact, all those numerals represent the same number, but no one of the numerals is the number. The number itself is an abstract idea that can be referred to using any of those numerals.

In the same way,

  • the Roman "Ⅴ",

  • the Braille "⠼⠑",

  • the Coptic Epact "𐋥",

  • the Eastern Arabic "٥",

  • the Western Arabic "5".

are other ways of representing the same number that the words above represent.

Semiotics
In semiotics, the study of signs, symbols, and signification, the number is a sign, made up of the signified mental concept and the signifier (the numeral.) Further discussion is beyond the scope of this textbook, and beyond the remixer’s expertise! Here is a link if you want to learn more about semiotics.
This is not a pipe!
Read this Wikipedia article and pay attention to the quote from the artist, René Magritte.

6.2. Review Of The Base-Ten Place Value System

It’s likely that everything you are about to read in this section is knowledge you’ve had for many years. The purpose of stating everything so explicitly is to provide an example you can compare with place-value systems that use other bases.

A base-ten numeral is a string formed from one or more digits (i.e., Hindu-Arabic numerals.)

  • The string is read from left-to-right.

  • Each digit in the string represents a multiple of a power of the base, ten, depending on the its position in the string.

  • The rightmost place represents a multiple of 1 (which is ten raised to the power zero) and each of the other places represents a multiple of a power of ten that is one greater than the power of ten represented by the place to its right.

  • Notice that the base itself, the number ten, is represented by the string "10" in this place-value system. The string "10" represents the number described by the phrase "1 ten plus 0 ones".

  • As an example, the string "101" represents the number described by the phrase "1 hundred plus 0 tens, plus 1 ones," where 1 hundred is the same as ten tens. That is, \[ 101 = 1 \cdot 10 \cdot 10 + 0 \cdot 10 + 1 \cdot 1 \] The expression on the right-hand side of the previous equation is referred to as expanded form in school-level mathematics.

NOTE: The Hindu-Arabic numerals evolved from earlier Brahmi versions. You can look at the image at this web page which shows a few steps in this evolution. Also, you can learn more about the history of the Hindu-Arabic numerals from the links in the "Notes" and "References" sections of this Wikipedia page.

6.2.1. An Algorithm That Computes The Digits Of A Base-Ten Numeral

In this subsection, an algorithm is presented for computing the digits in the expanded form of a base-ten numeral of the natural number \(n.\) This may seem to be a complicated way to do something very simple since we could just read off the digits, but the important thing to notice about this algorithm is that the role that ten plays can be played by any other positive integer constant greater than one! This means that this algorithm can be adapted to find the "digits" in the expanded form of a base-\(b\) numeral for the number \(n\) for any base \(b\) we choose.

  • Task: Given the natural number n, compute an array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] so that each of \(r_{0}, r_{1}, \ldots , r_{k}\) is represented by a single digit in base-10, and \[ n = r_{k} \cdot 10^{k} + \ldots + r_{1} \cdot 10^{1} + r_{0} \cdot 10^{0} \] where \(k\) is the greatest natural number such that \(10^{k} < n.\)

    • Input: The natural number \(n\)

    • Steps:

      1. Set \(a\) equal to \(n\)

      2. Set \(s\) to the empty array (We will append the values \(r_{0}, r_{1}, \ldots , r_{k}\) to the array \(s\) as we compute them)

      3. Divide \(a\) by 10 to find natural numbers \(q\) and \(r\) such that both \(a = q \cdot 10 + r\) and \(0 \leq r < 10.\)

      4. Append \(r\) to the end of array \(s.\)

      5. If \(q \neq 0\)

        1. set \(a\) equal to \(q\)

        2. go to step 3

      6. Return the sequence \(s.\)

    • Output: An array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] where each number is represented by a single digit, and \[ n = r_{k} \cdot 10^{k} + \ldots + r_{1} \cdot 10^{1} + r_{0} \cdot 10^{0}.\]

That is, we rewrite \(n\) as \(r_{0} + 10 \cdot (r_{1} + 10 \cdot (r_{2} + \ldots r_{k-1} + (10 \cdot (r_{k})) \ldots ))\)

Example 2 - Finding The Digits Of A Base-Ten Numeral

The following equations summarize how the preceding algorithm determines the digits in the base-ten expanded form numeral for the number 432.

\begin{equation} \begin{aligned} 432 {} & = 43 \cdot 10 + 2 & q {} & = 43 & r {} & = 2 & s & = [2] \\ 43 {} & = 4 \cdot 10 + 3 & q {} & = 4 & r {} & = 3 & s & = [2, 3] \\ 4 {} & = 0 \cdot 10 + 4 & q {} & = 0 & r {} & = 4 & s & = [2, 3, 4] \\ \end{aligned} \end{equation}

Notice that the items in \(s = [ r_{0}, \, r_{1}, \, r_{2} \)] are the numbers corresponding to the digits of the numeral \(“432”\) in reverse order, so \begin{equation} \begin{aligned} 432 & = r_{2} \cdot 10^{2} + r_{1} \cdot 10^{1} + r_{0} \cdot 10^{0} \\ & = 4 \cdot 10^{2} + 3 \cdot 10^{1} + 2 \cdot 10^{0} \end{aligned} \end{equation}

Notice that the algorithm is rewriting \(432\) as the sum \(2 + 10 \cdot (3 + 10 \cdot 4)).\)

6.3. The Base-Two Place Value System (Binary Notation)

This subsection describes the base-two (binary) place value system. You will see that much of what is written here is the result of replacing "ten" by "two" in the description of the base-ten (decimal) system in the previous section.

A base-two numeral is a string formed from one or more of the two binary digits (or bits ) ‘0’ and ‘1’.

  • The string is read from left-to-right.

  • Each digit in the string represents a multiple of a power of the base, two, depending on the its position in the string.

  • The rightmost place represents a multiple of 1 (which is two raised to the power zero) and each of the other places represents a multiple of a power of two that is one greater than the power of two represented by the place to its right.

  • Notice that the base itself, the number two, is represented by the string "10" in this place-value system. The string "10" represents the number described by the phrase "1 two plus 0 ones".

  • As an example, the string "101" represents the number described by the phrase "1 four plus 0 twos, plus 1 ones," where 1 four is the same as two twos. That is, \[ 101 = 1 \cdot 10 \cdot 10 + 0 \cdot 10 + 1 \cdot 1 \text{ (🤯: Wait…​ WHAT?!?) }\] Yes, this equation, which may appear to be written in the base-ten system, is correct in the base-two place value system, too! "10" is how the number two is represented in base-two notation!
    As an analogy, the string "pie" signifies different things in English (a baked dessert) and Spanish (a foot.) You must take care to know which context you are working in!

It is traditional to use some extra notation to indicate when the strings "10" and "101" are not base-ten numerals to avoid confusion. In this textbook, numerals in any base other than ten will be written between a pair of parentheses followed by a subscript indicating the base. The subscript is written as a base-ten numeral. For example, we could rewrite the previous equation as \[(101)_{2} = (1)_2 \cdot (10)_2 \cdot (10)_2 + (0)_2 \cdot (10)_2 + (1)_2 \cdot (1)_2 \] which translates into base-ten as \(5 = 1 \cdot 2 \cdot 2 + 0 \cdot 2 + 1 \cdot 1.\) We can also write \(5 = (101)_2\) which is a way of saying that the base-ten numeral and the base-two numeral signify the same number. + NOTE: The reason we use base-ten numerals as the subscripts on numerals in other bases is because base-ten is so dominant: It is the "privileged" base, so we need to indicate when a different base is being used…​ and we don’t need to use the parentheses or subscripts if we are already working in base-ten.

The parentheses and subscript are not necessary if it is clear from the context that a numeral is not a base-ten numeral. For example, \[ \text{chmod 755 hello.txt} \] is a Unix/Linux command that changes the file permission bits (read, write, execute) of the file "hello.txt" for the file’s owner, the file’s group, and any other user. In this example, the string "755" is not a base-10 numeral, but is in octal (base-eight). Octal will be discussed later in the chapter. No subscript is used in the Unix/Linux command because it is natural to an experienced user of that operating system to use octal in the context.
In fact, the octal numeral "755" is used here as an encoding of three bitstrings, where each bitstring is of length 3; this idea is discussed in a later subsection of this chapter.

Also, we can omit the parentheses and subscripts if we want to tell a couple of "jokes:"

You are ready now to learn how to represent numbers using base-two numerals.

6.3.1. An Algorithm That Computes The Digits Of A Base-Two Numeral

In this subsection, an algorithm is presented for computing the digits in the expanded form of a base-two numeral of the natural number \(n.\) This algorithm has been adapted from the one stated for base-ten in the previous section. Notice that all numerals used in this algorithm are base-ten numerals unless otherwise indicated.

  • Task: Given the natural number n, compute an array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] so that each of \(r_{0}, r_{1}, \ldots , r_{k}\) is represented by a single digit in base-2, and \[ n = r_{k} \cdot 2^{k} + \ldots + r_{1} \cdot 2^{1} + r_{0} \cdot 2^{0} \] where \(k\) is the greatest natural number such that \(2^{k} < n.\)

    • Input: The natural number \(n\)

    • Steps:

      1. Set \(a\) equal to \(n\)

      2. Set \(s\) to the empty array (We will append the values \(r_{0}, r_{1}, \ldots , r_{k}\) to the array \(s\) as we compute them)

      3. Divide \(a\) by 2 to find natural numbers \(q\) and \(r\) such that both \(a = q \cdot 2 + r\) and \(0 \leq r < 2.\)

      4. Append \(r\) to the end of array \(s.\)

      5. If \(q \neq 0\)

        1. set \(a\) equal to \(q\)

        2. go to step 3

      6. Return the sequence \(s.\)

    • Output: An array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] where each number is represented by a single digit, and \[ n = r_{k} \cdot 2^{k} + \ldots + r_{1} \cdot 2^{1} + r_{0} \cdot 2^{0}.\]

That is, the algorithm rewrites \(n\) as \(r_{0} + 2 \cdot (r_{1} + 2 \cdot (r_{2} + \ldots r_{k-1} + (2 \cdot (r_{k})) \ldots ))\)

Example 3 - Finding The Digits Of A Base-Two Numeral (Binary Notation)

The following equations summarize how the preceding algorithm determines the digits in the base-two expanded form numeral for the number 13.

\begin{equation} \begin{aligned} 13 {} & = 6 \cdot 2 + 1 & q {} & = 6 & r {} & = 1 & s & = [1] \\ 6 {} & = 3 \cdot 2 + 0 & q {} & = 3 & r {} & = 0 & s & = [1, 0] \\ 3 {} & = 1 \cdot 2 + 1 & q {} & = 1 & r {} & = 1 & s & = [1, 0, 1] \\ 1 {} & = 0 \cdot 2 + 1 & q {} & = 0 & r {} & = 1 & s & = [1, 0, 1, 1] \\ \end{aligned} \end{equation}

Notice that the items in \(s = [ r_{0}, \, r_{1}, \, r_{2} , \, r_{3} \)] are the numbers (in base-ten notation) corresponding to the digits of the numeral \(“(1101)_2”\) in reverse order, so \begin{equation} \begin{aligned} 13 & = r_{3} \cdot 2^{3} + r_{2} \cdot 2^{2} + r_{1} \cdot 2^{1} + r_{0} \cdot 2^{0} \\ & = 1 \cdot 2^{3} + 1 \cdot 2^{2} + 0 \cdot 2^{1} + 2 \cdot 2^{0} \end{aligned} \end{equation}

The algorithm rewrites \(13\) as \(1 + 2 \cdot (0 + 2 \cdot (1 + 1 \cdot 2))).\)
Again, notice that the items in the array \([1, 0, 1, 1\)] are listed in reverse order, so \(13 = (1101)_2\) where the base-ten numeral and the base-two numeral represent the same number, thirteen.

Here is a link to an alternate method of finding the base-two numeral for a number.

If you made it to this sentence without skipping any of the discussion above, congratulations! If you did skip some of the discussion, go back and try your best to understand what the algorithm in the previous example is computing: The array \(s\) holds the digits, in reverse order of the binary notation for the number \(n.\) Compare what is done in this algorithm to the one for base-ten in the previous section…​ they are computing the digits for a numeral, but in different bases. If you can understand this algorithm, you will likely understand the rest of the chapter.

6.4. The Base-\(b\) Place Value System

If you made it here, you are ready to learn how to find, given any natural number \(n,\) the numeral that represents \(n\) in the base-\(b\) place value system (It is assumed that the base \(b\) is a natural number greater than or equal to 2.) You can compare the algorithm and example in this subsection to the ones in the preceding subsections for base-ten and base-two.

A base-\(b\) numeral is a string formed from one or more digits out of a set that contains \(b\) symbols, where each symbol is called a "base-\(b\) digit."

  • The string is read from left-to-right.

  • Each digit in the string represents a multiple of a power of the base, \(b,\) depending on the its position in the string.

  • The rightmost place represents a multiple of 1 (which is \(b\) raised to the power zero) and each of the other places represents a multiple of a power of \(b\) that is one greater than the power of \(b\) represented by the place to its right.

  • Notice that the base itself, the number \(b,\) is represented by the string "10" in the base-\(b\) place value system. The string "10" represents the number described by the phrase "1 \(b\) plus 0 ones".

  • As an example, the string "101" represents the number described by the phrase "1 b-_squared plus 0 _b , plus 1 ones." That is, \[ 101 = 1 \cdot 10 \cdot 10 + 0 \cdot 10 + 1 \cdot 1 \text{ (🤯: Again?!?) }\] Yes, this equation is correct, too, in the base-b place value system!

To avoid confusion, you can enclose each numeral in a pair of parentheses followed by the subscript \(b\) to indicate the base, where \(b\) is written as a base-ten numeral. For example, the previous equation can be written as \[(101)_{b} = (1)_b \cdot (10)_b \cdot (10)_b + (0)_b \cdot (10)_b + (1)_b \cdot (1)_b \] which translates into base-ten as \(b^2 + 1 = 1 \cdot b \cdot b + 0 \cdot b + 1 \cdot 1.\)

6.4.1. An Algorithm That Computes The Digits Of A Base-\(b\) Numeral

This is an adaptation of the algorithm presented earlier for base-two. Notice that all numerals used in this algorithm are base-ten numerals unless otherwise indicated.

  • Task: Given the natural number n, and positive integer constant \(b > 1\) compute an array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] so that each of \(r_{0}, r_{1}, \ldots , r_{k}\) can be represented by a single digit in base-\(b\), and \[ n = r_{k} \cdot b^{k} + \ldots + r_{1} \cdot b^{1} + r_{0} \cdot b^{0} \] where \(k\) is the greatest natural number such that \(b^{k} < n.\)

    • Input: The natural number \(n\)

    • Steps:

      1. Set \(a\) equal to \(n\)

      2. Set \(s\) to the empty array (We will append the values \(r_{0}, r_{1}, \ldots , r_{k}\) to the array \(s\) as we compute them)

      3. Divide \(a\) by \(b\) to find natural numbers \(q\) and \(r\) such that both \(a = q \cdot b + r\) and \(0 \leq r < b.\)

      4. Append \(r\) to the end of array \(s.\)

      5. If \(q \neq 0\)

        1. set \(a\) equal to \(q\)

        2. go to step 3

      6. Return the sequence \(s.\)

    • Output: An array of natural numbers \(s = [ r_{0}, \, r_{1}, \, \ldots \, r_{k} \)] where each number is represented by a single digit in base-\(b,\) and \[ n = r_{k} \cdot b^{k} + \ldots + r_{1} \cdot b^{1} + r_{0} \cdot b^{0}.\]

The algorithm rewrites \(n\) as \(r_{0} + b \cdot (r_{1} + b \cdot (r_{2} + \ldots r_{k-1} + (b \cdot (r_{k})) \ldots )).\) The result \(s\) contains the numbers that let you write \(n\) in base-\(b\) notation.

6.4.2. Octal Notation (Base-8)

Example 4 - Finding The Digits Of A Base-8 Numeral (Octal Notation)

The following equations summarize how to determine the digits in the base-8 expanded form numeral for the number 100.

Note that for base-8 we use the eight digits ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, and ‘7’.

\begin{equation} \begin{aligned} 100 {} & = 12 \cdot 8 + 4 & q {} & = 12 & r {} & = 4 & s & = [4] \\ 12 {} & = 1 \cdot 8 + 4 & q {} & = 1 & r {} & = 4 & s & = [4, 4] \\ 1 {} & = 0 \cdot 8 + 1 & q {} & = 0 & r {} & = 1 & s & = [4, 4, 1] \\ \end{aligned} \end{equation}

Notice that \(s = [ 4, \, 4, \, 1 \)] are the numbers (in base-ten notation) corresponding to the base-8 digits of the numeral \(“(144)_8”\) in reverse order. You can verify that \(100 = 1 \cdot 8^{2} + 4 \cdot 8^{1} + 4 \cdot 8^{0}.\) This means that \(100 = (144)_8.\)

6.4.3. Hexadecimal Notation (Base-16)

Example 5 - Finding The Digits Of A Base-16 Numeral (Hexadecimal Notation)

The following equations summarize how to determine the digits in the base-16 expanded form numeral for the number 500.

Note that for base-16, we need sixteen digits! It is traditional to use the ten Hindu-Arabic numerals followed by the first six uppercase English letters as the digits: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, and ‘F’. So \(10 = (A)_{16},\) \(11 = (B)_{16},\) \(12 = (C)_{16},\) \(13 = (D)_{16},\) \(14 = (E)_{16},\) and \(15 = (F)_{16}.\)
Note: Some programming languages like Python use the lowercase letters 'a' through 'f' instead of the uppercase letters.

The remainders stored in the array \(s\) are represented in base-ten notation, and will need to be replaced by the corresponding hexadecimal digits in the base-16 numeral for 500.

\begin{equation} \begin{aligned} 500 {} & = 31 \cdot 16 + 4 & q {} & = 31 & r {} & = 4 & s & = [4] \\ 31 {} & = 1 \cdot 16 + 15 & q {} & = 1 & r {} & = 15 & s & = [4, 15] \\ 1 {} & = 0 \cdot 16 + 1 & q {} & = 0 & r {} & = 1 & s & = [4, 15, 1] \\ \end{aligned} \end{equation}

As before, we have \(500 = 1 \cdot 16^{2} + 15 \cdot 16^{1} + 4 \cdot 16^{0},\) which you can verify is true. To write the base-16 numeral for 500, you need to replace "15" in base-ten by \((F)_{16}.\) So \(500 = (1F4)_{16}.\)

6.4.4. A Theorem (To Be Proven Later)

We can summarize what the algorithm does as a mathematical theorem, though technically at this point, it’s only a conjecture, an educated guess based on a few cases that seem to indicate that the algorithm will always work. You will learn a technique that will prove the theorem by validating the algorithm for all choices of natural numbers \(n\) and \(b>1\) in the Proofs: Mathematical Induction chapter.

Theorem

Let \(b\) be an integer greater than 1. Any positive integer \(n\) can be expressed uniquely in the form \[n = r_kb^k + r_{k - 1}b^{k-1} + \cdots + r_1b^1 + r_0b^0,\]where \(k\) is a nonnegative integer, \(r_0,r_1,\dots,r_k\) are nonnegative integers less than \(b,\) and \(r_k \neq 0.\)

6.5. Converting From Base-\(b\) to Base-Ten

In this section you will learn how to rewrite a base-\(b\) numeral in base-ten.

Example 6

What is the decimal expansion of the positive integer with base 7 expansion \((1063)_7\)?

Solution

We have

\[\begin{split} (1063)_7 &= 1 \cdot 7^3 + 0 \cdot 7^2 + 6\cdot 7^1 + 3 \cdot 7^0\\ &=1 \cdot 343 + 0 \cdot 49 + 6 \cdot 7 + 3 \cdot 1\\ &= 343 + 0 + 42 + 3\\ &= 388. \end{split}\]

Several common bases used in computer science are base \(2\), base \(8\), and base \(16\), which are referred to as binary , octal , and hexadecimal , respectively. Binary digits are often referred to as bits . Note that, when finding the hexadecimal expansion of a positive integer, in addition to the usual digits \(0\) through \(9,\) we require an additional 6 digits. We will represent these by the letters \(\mathrm{A}\) through \(\mathrm{F}\), where \((\mathrm{A})_{16} = 10,\) \((\mathrm{B})_{16} = 11,\) \((\mathrm{C})_{16} = 12,\) \((\mathrm{D})_{16} = 13,\) \((\mathrm{E})_{16} = 14,\) and \((\mathrm{F})_{16} = 15.\)

Example 7 - Hexadecimal expansion

Find the decimal expansion of the positive integer whose hexadecimal expansion is \((5\mathrm{B}\mathrm{F})_{16}.\)

Solution

We have

\[\begin{split} (5\mathrm{B}\mathrm{F})_{16} &= 5\cdot 16^2 + 11 \cdot 16^1 + 15 \cdot 16^0\\ &= 5\cdot 256 + 11 \cdot 16 + 15 \cdot 1\\ &= 1280 + 176 + 15\\ &= 1471. \end{split}\]

6.6. Base Conversion Among Binary, Octal, and Hexadecimal

One of the ways that octal (base-eight) and hexadecimal (base-sixteen) are used in computer science is to abbreviate long bitstrings. The following examples will show how this is done.

Suppose you need to convert a numeral from hexadecimal to binary. One method would be to first convert from hexadecimal to decimal, and then convert the result from decimal to binary. However, it is much more efficient to notice that since \(2^4 = 16,\) you can express each hexadecimal digit as a block of 4 bits (that is, a bitstring of length 4) as follows:

\[\begin{array}{llll} (0)_{16} = (0000)_2 & (1)_{16} = (0001)_{2}& (2)_{16} = (0010)_2 & (3)_{16} = (0011)_2 \\ (4)_{16} = (0100)_2& (5)_{16} = (0101)_2& (6)_{16} = (0110)_2 & (7)_{16} = (0111)_2\\ (8)_{16} = (1000)_2& (9)_{16} = (1001)_2& (\mathrm{A})_{16} = (1010)_2& (\mathrm{B})_{16} = (1011)_2\\ (\mathrm{C})_{16} = (1100)_2& (\mathrm{D})_{16} = (1101)_2& (\mathrm{E})_{16} = (1110)_2& (\mathrm{F})_{16} = (1111)_2. \end{array}\]

You can then concatenate the blocks, and remove any leading zeros if you need to.

Example 8 - Hexadecimal to Binary Conversion

Find the binary expansion of \((4\mathrm{C}\mathrm{A}7)_{16}.\)

Solution

Each hexadecimal digit can be replaced by a block of 4 bits:

\[\begin{array}{llll} (4)_{16} = (0100)_2 & (\mathrm{C})_{16} = (1100)_2 & (\mathrm{A})_{16} = (1010)_2 & (7)_{16} = (0111)_2. \end{array}\]

This means that you can write either \[(4\mathrm{C}\mathrm{A}7)_{16} = (0100110010100111)_{2}\] or, if the leading zero is not needed, \[(4\mathrm{C}\mathrm{A}7)_{16} = (100110010100111)_{2}.\] Why wouldn’t you always delete leading zeroes? Notice that a bitstring of length 4 can be used to encode a sequence of "Yes/No" or "True/False" answers. As an example, since \((6)_{16} = (0110)_2,\) the hexadecimal digit \((6)_{16}\) can be used to encode the sequence of 4 answers "No, Yes, Yes, No" to a Yes/No survey, and in this context the leftmost bit should be kept to make it clear that the answer to the first question was "No" (as opposed to the sequence "Yes, Yes, No, blank" where the fourth question was not answered.)

To convert a numeral from binary to hexadecimal, first break up the binary notation into blocks of 4 bits, adding a suitable number of leading zeros if necessary. Next, convert each block of 4 bits to a hexadecimal digit and concatenate the results, removing any leading zeros if necessary.

Example 9 - Binary to Hexadecimal Conversion

Find the hexadecimal expansion of \((110 1011 1111)_2.\)

Solution

The are three blocks of 4 bits: \[0110,\ 1011,\ 1111.\] Since \((0110)_2 = (6)_{16},\) \((1011)_2 = (\mathrm{B})_{16},\) and \((1111)_2 = (\mathrm{F})_{16},\) \[(11010111111)_{2} = (6\mathrm{B}\mathrm{F})_{16}.\]

A similar method can be used to convert between octal and binary. Since \(2^3 = 8,\) each octal digit can be written uniquely as a block of 3 bits as follows:

\[\begin{array}{llll} (0)_{8} = (000)_2 & (1)_{8} = (001)_{2}& (2)_{8} = (010)_2 & (3)_{8} = (011)_2 \\ (4)_{8} = (100)_2& (5)_{8} = (101)_2& (6)_{8} = (110)_2 & (7)_{8} = (111)_2. \end{array}\]

We then concatenate blocks, removing any leading zeros if necessary.

Also, the following table can be used to covert quickly between decimal, hexadecimal, octal, and binary in a similar way.

Conversion table for different bases

Decimal

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Hexadecimal

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Octal

0

1

2

3

4

5

6

7

10

11

12

13

14

15

16

17

Binary

0

1

10

11

100

101

110

111

1000

1001

1010

1011

1100

1101

1110

1111

6.7. Exercises

  1. Convert to decimal (base 10)

    1. \((10262)_7\)

    2. \((30A8)_{16}\)

    3. \((1000010001100)_2\)

    4. \(({12307)}_{60}\)

  2. Convert \(\left(2039\right)_{10}\) from decimal (base 10) to

    1. base 7

    2. binary

    3. hexadecimal (base 16)

    4. octal (base 8)

  3. Convert \(\left(2599\right)_{10}\) from decimal to

    1. base 5

    2. binary

    3. hexadecimal

    4. base 3

  4. Convert the following hexadecimal numerals to binary numerals

    1. \(\left(6F203\right)_{16}\)

    2. \(\left(3FA20C45\right)_{16}\)

    3. \(\left(FACE\right)_{16}\)

  5. Convert the following binary numerals to hexadecimal numerals

    1. \(\left(1111100111010101101\right)_2\)

    2. \(\left(\ 10001111101011\right)_2\)

    3. \(\left(1100101011111110\right)_2\)