Number Systems: Conversion involved a binary number system

Binary (Base 2), quaternary (base 4), octal (base 8), hexadecimal (base 16) systems

Number Systems – Part 1 and Number Systems – Part 2 discuss meaning of number systems (or numbering systems) and how to convert a number from one base to another base via the decimal number system. This article will discuss the relationship between binary numbers and quaternary, octal, and hexadecimal numbers, and describe a simpler way to convert these numbers to binary numbers and vice versa.

A. Conversion to binary numbers

Quaternary numbers (Base-4)

To convert a quaternary number (base 4), for example 203.12, to a binary number (base 2), note that 4 = 22, and number 203.12 can be expressed as Eq. A.1 (as stated in Number Systems – Part 1)

\textsf{\textbf{\small{Eq. A.1:}}}
  \textsf{(203.12)_{\textcolor{blue}{4}} &= (\textcolor{red}{2}\times\textcolor{blue}{4}^2) + (\textcolor{red}{0} \times\textcolor{blue}{4}^1) + (\textcolor{red}{3}\times\textcolor{blue}{4}^0) + (\textcolor{red}{1}\times\textcolor{blue}{4}^{-1})  + (\textcolor{red}{2}\times\textcolor{blue}{4}^{-2}) }

Substituting 4 = 22 in Eq. A.1, we get

\textsf{\textbf{\small{Eq. A.2:}}}
 \textsf{ (203.12)_{\textcolor{blue}{4}} &= (\textcolor{red}{2}\times\textcolor{blue}{2}^4) + (\textcolor{red}{0} \times\textcolor{blue}{2}^2) + (\textcolor{red}{3}\times\textcolor{blue}{2}^0) + (\textcolor{red}{1}\times\textcolor{blue}{2}^{-2})  + (\textcolor{red}{2}\times\textcolor{blue}{2}^{-4}) }

In the binary number system, numbers 0, 1, 2, and 3 are represented as

 \textsf{\small{\textbf{Eq. A.3:}}}
  \begin{alignat*}{3} &\quad & 0_{\textcolor{blue}{4}} &= \textcolor{red}{0}\times\textcolor{blue}{2}^1 + \textcolor{red}{0} \times\textcolor{blue}{2}^0  &= 00_{\textcolor{blue}{2}}\\ & \quad & 1_{\textcolor{blue}{4}} &= \textcolor{red}{0}\times\textcolor{blue}{2}^1 + \textcolor{red}{1} \times\textcolor{blue}{2}^0  &= 01_{\textcolor{blue}{2}}\\ & \quad & 2_{\textcolor{blue}{4}} &= \textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{0} \times\textcolor{blue}{2}^0  &= 10_{\textcolor{blue}{2}}\\ &\quad & 3_{\textcolor{blue}{4}} &= \textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{1} \times\textcolor{blue}{2}^0  &= 11_{\textcolor{blue}{2}}\\ \end{align*}

Thus Eq. A.2 can be written as

 \textsf{\small{\textbf{Eq. A.4a:}}}
  \renewcommand{\arraystretch}{1.5} \textsf{  \begin{tabular}{l r c p{270px}  r } & (203.12)_{\textcolor{blue}{4}} &= &((\textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{0} \times\textcolor{blue}{2}^0)\times\textcolor{blue}{2}^4) +   ((\textcolor{red}{0}\times\textcolor{blue}{2}^1 + \textcolor{red}{0} \times\textcolor{blue}{2}^0)\times\textcolor{blue}{2}^2) + & \\  & & &((\textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{1} \times\textcolor{blue}{2}^0 )\times\textcolor{blue}{2}^0) + ((\textcolor{red}{0}\times\textcolor{blue}{2}^1 + \textcolor{red}{1} \times\textcolor{blue}{2}^0)\times\textcolor{blue}{2}^{-2})  + & \\ & &  &  ((\textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{0} \times\textcolor{blue}{2}^0 )\times\textcolor{blue}{2}^{-4}) & \end{tabular} }

or

 \textsf{\small{\textbf{Eq. A.4b:}}}
  \renewcommand{\arraystretch}{1.5} \textsf{  \begin{tabular}{l r c p{270px}  r } &  (203.12)_{\textcolor{blue}{4}}  & = & \textcolor{red}{1}\times\textcolor{blue}{2}^5 + \textcolor{red}{0} \times\textcolor{blue}{2}^4 + \textcolor{red}{0}\times\textcolor{blue}{2}^3 + \textcolor{red}{0} \times\textcolor{blue}{2}^2 + \textcolor{red}{1}\times\textcolor{blue}{2}^1 + \textcolor{red}{1} \times\textcolor{blue}{2}^0  + &  \\ & & & \textcolor{red}{0}\times\textcolor{blue}{2}^{-1} + \textcolor{red}{1} \times\textcolor{blue}{2}^{-2} + \textcolor{red}{1}\times\textcolor{blue}{2}^{-3} + \textcolor{red}{0} \times\textcolor{blue}{2}^{-4} &  \end{tabular} }

or

 %\renewcommand{\arraystretch}{1.5} \textsf{\small{\textbf{Eq. A.4c:}}}
  \renewcommand{\arraystretch}{1.5} \textsf{  \begin{tabular}{l r c p{270px}  r } \implies &(203.12)_{\textcolor{blue}{4}} & = &(100011.0110)_{\textcolor{blue}{2}} &  \end{tabular} }

Comparing Eqs. A.1, A.3, and A.4b, it can be concluded that to convert a quaternary number to a binary number, we can simply replace each quaternary digit with its equivalent 2-bit binary. Matching color for each quaternary digit and its equivalent 2-bit binary number in Eq. A.4c is used to demonstrate this conversion approach as shown below (note that the binary number 110011.0110 can be expressed as 110011.011)

  \Large{(\textcolor{red}{2}\textcolor{green}{0}\textcolor{brown}{3}.\textcolor{magenta}{1}\textcolor{violet}{2})_{\textcolor{blue}{4}} \longrightarrow (\textcolor{red}{1}\textcolor{red}{0}\textcolor{green}{0}\textcolor{green}{0}\textcolor{brown}{1}\textcolor{brown}{1}.\textcolor{magenta}{0}\textcolor{magenta}{1}\textcolor{violet}{1}\textcolor{violet}{0})_{\textcolor{blue}{2}}}

Octal numbers (Base-8)

A similar method can be used for conversion of octal numbers to binary numbers, except that, as the base of an octal number is 8, which is 23, an octal digit must be replaced with a 3-bit binary number instead of 2-bit. 3-bit binary number for each of eight octal digits can be derived in the same way as that of Eq. A.3; and similarly 4-bit binary numbers for 16 hexadecimal digits. 2-bit, 3-bit, and 4-bit binary numbers for each of quaternary, octal, and hexadecimal digits are shown in Table A.1 below.

For example, conversion of octal number 72 to binary:

 \textsf{ \Large{(\textcolor{red}{7}\textcolor{green}{2})_{\textcolor{blue}{8}} = (\textcolor{red}{1}\textcolor{red}{1}\textcolor{red}{1}\textcolor{green}{0}\textcolor{green}{1}\textcolor{green}{0})_{\textcolor{blue}{2}}} }

Converting octal number 72.03 to binary:

 \textsf{ \Large{(\textcolor{red}{7}\textcolor{green}{2}.\textcolor{brown}{0}\textcolor{magenta}{3})_{\textcolor{blue}{8}} = (\textcolor{red}{1}\textcolor{red}{1}\textcolor{red}{1}\textcolor{green}{0}\textcolor{green}{1}\textcolor{green}{0}.\textcolor{brown}{0}\textcolor{brown}{0}\textcolor{brown}{0}\textcolor{magenta}{0}\textcolor{magenta}{1}\textcolor{magenta}{1})_{\textcolor{blue}{2}}} }

Hexadecimal numbers (Base-16)

Similarly, to convert a hexadecimal number to binary number, note that hexadecimal number has a base of 16, which is 24, so a 4-bit binary number will be used to replace each hexadecimal digit.

For example, to convert hexadecimal number A1E to binary number, we substitute A, 1, and B with their respective 4-bit binary number as below

 \textsf{ \Large{(\textcolor{red}{A}\textcolor{green}{1}\textcolor{brown}{E})_{\textcolor{blue}{16}} = (\textcolor{red}{1}\textcolor{red}{0}\textcolor{red}{1}\textcolor{red}{0}\textcolor{green}{0}\textcolor{green}{0}\textcolor{green}{0}\textcolor{green}{1}\textcolor{brown}{1}\textcolor{brown}{1}\textcolor{brown}{1}\textcolor{brown}{0})_{\textcolor{blue}{2}}} }

and converting hexadecimal number A1E.2D to binary number can be done in a similar fashion:

 \textsf{ \Large{(\textcolor{red}{A}\textcolor{green}{1}\textcolor{brown}{E}.\textcolor{magenta}{2}\textcolor{violet}{D})_{\textcolor{blue}{16}} = (\textcolor{red}{1}\textcolor{red}{0}\textcolor{red}{1}\textcolor{red}{0}\textcolor{green}{0}\textcolor{green}{0}\textcolor{green}{0}\textcolor{green}{1}\textcolor{brown}{1}\textcolor{brown}{1}\textcolor{brown}{1}\textcolor{brown}{0}.\textcolor{magenta}{0}\textcolor{magenta}{0}\textcolor{magenta}{1}\textcolor{magenta}{0}\textcolor{violet}{1}\textcolor{violet}{1}\textcolor{violet}{0}\textcolor{violet}{1})_{\textcolor{blue}{2}}} }


B. binary numbers to quaternary, octal, & hexadecimal numbers

Conversion of a binary number to quaternary, or octal, or hexadecimal number is the reverse of the above process with 2-bit binary for quaternary, 3-bit for octal, and 4-bit for hexadecimal. Also, for the whole number part, the replacement starts from right to left, and padding of zeros may be needed to the last left digit to make up for its respective bit size. For the fractional part, if any, the replacement starts from the fractional point and from left to right, and padding of zeros may be needed to the last right digit to make up for the respective bit size.

Quaternary Numbers

To convert a binary number, says 1011, to quaternary, we start with substituting the last two digits, 11, with 3 , then binary digits 10 with 2 and adding it to the left of 3 to make quaternary number 23.

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{l r c l} \implies & (1011)_{\textcolor{blue}{2}}  &= &(23)_{\textcolor{blue}{4}}  \end{tabular} }

To convert binary number 11011, after replacing 11 with 3 and 10 with 2, a zero is padded to the left of the remaining binary digit 1 to make a 2-bit binary 01, which is 1 in quaternary system. The quaternary result is 123, and the padded zero is highlighted in red as shown below,

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{{l r c l}} \implies &(11011)_{\textcolor{blue}{2}} &= &(123)_{\textcolor{blue}{4}}  \end{tabular} }

To convert binary number 11011.011 to quaternary number, the whole number (before the fractional point) is equal to quaternary 123, as explained earlier. For the fractional part, we start with 01, the first two digits immediately on the right of the fractional point, which has quaternary value of 1 (see Table A.1); we then add a zero to the right of the remaining 1 to make 2-bit binary 10. The resulted quaternary number is shown below, padded zeros are in red color for the whole number part and green for the fractional part.

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{l r c l} \implies &(11011.011)_{\textcolor{blue}{2}} &= &(123.12)_{\textcolor{blue}{4}}  \end{tabular} }

Octal numbers

To convert binary number 1011 to octal, similar steps can be used but with 3-bit binary.

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{l r c l} \implies &(1011)_{\textcolor{blue}{2}} &= &(13)_{\textcolor{blue}{8}}  \end{tabular} }

Convert binary 11011.011 to octal number:

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{{l r c l}} \implies &(11011.011)_{\textcolor{blue}{2}} &= &(33.3)_{\textcolor{blue}{8}}  \end{tabular} }

Hexadecimal Numbers

Converting binary number 1011 to hexadecimal number

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{{l r c l}} \implies &(1011)_{\textcolor{blue}{2}} &= &(B)_{\textcolor{blue}{16}}  \end{tabular} }

Converting binary number 11011.011 to hexadecimal number

  \renewcommand{\arraystretch}{1.5} \textsf{   \begin{tabular}{{l r c l}} \implies &(11011.011)_{\textcolor{blue}{2}} &= &(1B.6)_{\textcolor{blue}{16}}  \end{tabular} }


Binary equivalents of quaternary, octal, & hexadecimal numbers

\textbf{Table A.1:} Binary number equivalents for quaternary, octal, and hexadecimal numbers
  \textsf{ \begin{center}   \begin{tabular}{ | c | c | c | l | }     \hline      Quaternary & Octal & Hexadecimal & Binary\\      \hline       0& &  & 00  \\ \hline       1  & & & 01  \\ \hline       2  & &  & 10  \\ \hline       3  & &  & 11  \\      \hline             & 0 &  & 000  \\ \hline          & 1 &  & 001  \\ \hline          & 2 &  & 010  \\ \hline          & 3 &  & 011  \\ \hline          & 4 &  & 100  \\ \hline          & 5 &  & 101  \\ \hline          & 6 &  & 110  \\ \hline          & 7 &  & 111  \\ \hline          &  &  0 & 0000  \\ \hline          &  &  1 & 0001  \\ \hline          &  &  2 & 0010  \\ \hline          &  &  3 & 0011  \\ \hline          &  &  4 & 0100  \\ \hline          &  &  5 & 0101  \\ \hline          &  &  6 & 0110  \\ \hline          &  &  7 & 0111  \\ \hline          &  &  8 & 1000  \\ \hline          &  &  9 & 1001  \\ \hline          &  &  A & 1010  \\ \hline          &  &  B & 1011  \\ \hline          &  &  C & 1100  \\ \hline          &  &  D & 1101  \\ \hline          &  &  E & 1110  \\ \hline          &  &  F & 1111  \\ \hline  \end{tabular} \end{center} }


Number Systems – Part 1: Conversion to Decimal number system

Number Systems – Part 2: Conversion of decimal numbers to other number systems

Check your number

Enter your number (Number), its base (Number Base), and the new number base (New Base). The result (New Number) will appear inside the yellow box.

Convert a number to a different number system

Number Base: New Base:
Number: New Number: