Number System and Base Conversion

The numbers we are familiar with and use every day are based on 10 symbols and rules for making and displaying all numbers, both positive and negative, from them. This system of numbers is the decimal system

Note that in the decimal system the base is 10; we have 10 symbols, and the first number is 0. After counting to 9, the next number is composed of two digits: a 1 followed by the very first number, 0.

Consider an ordinary number such as 543. Because we are used to ordinary numbers like 543, it is not necessary to indicate its base. Otherwise, we would have to write it as 54310, showing that its base is 10, or it is a number written in a decimal system.

The meaning of the number 543 is as follows:

$543=5\times 100+4\times 10+3\times 1=5\times {{10}^{2}}+4\times {{10}^{1}}+3\times {{10}^{0}}$

(Remember that any number raised to power 0 is equal to 1.) Also, note that any number multiplied by 10 receives an additional zero at its right, or if divided by 10 loses its rightmost digit (The rightmost digit is the least significant digit. We may need to round a number):

$\begin{align}& 543\times 10=5430 \\& 5430\div 10=54\left( +0.3 \right) \\\end{align}$

All these and other rules are applicable to any other number system. We are going to see only 3 other number systems: hexadecimal, octal, and binary numbers. These are widely employed in the development or usage of industrial and domestic digital products.

All that is done in calculators, computers, and the like are practically based on the binary system, but for presentations, analysis, discussions, and theorem formulations, hexadecimal and octal systems are used. The reason for using hexadecimal and octal numbers is the convenience in converting from binary to those and vice versa. Conversion between decimal and binary numbers is not as convenient.

Hexadecimal Number System

Hexadecimal represents a number system whose base is 16 (made out of the Greek word hex for 6 and decimal denoting association with 10). Initially, therefore, 16 symbols are necessary to represent all numbers. Also, in writing hexadecimal numbers it is necessary to somehow indicate that its base is 16 and not 10.

The 16 numbers for the base of the hexadecimal system are numbers 0 to 15. For numbers 0 to 9 the same symbols used in the decimal system are employed. For numbers 10 to 15 the letters A to F are utilized, without any name. The base for the hexadecimal system is then

\[\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}0 & 1 & 2 \\\end{matrix} & 3 & 4 \\\end{matrix} & 5 & 6 \\\end{matrix} & 7 & 8 \\\end{matrix} & 9 & A \\\end{matrix} & B & C \\\end{matrix} & D & \begin{matrix}E & F \\\end{matrix} \\\end{matrix}\]

And their corresponding decimal values are

\[\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}\begin{matrix}0 & 1 & 2 \\\end{matrix} & 3 & 4 \\\end{matrix} & 5 & 6 \\\end{matrix} & 7 & 8 \\\end{matrix} & 9 & 10 \\\end{matrix} & 11 & 12 \\\end{matrix} & 13 & \begin{matrix}14 & 15 \\\end{matrix} \\\end{matrix}\]

The following number after F in the hexadecimal system is 10, in the same way, that in decimal numbers after 9 we have 10. To show that a number is written in the hexadecimal system (or its base is 16), we can put the base as a subscript for the number, like 54316. A more common way is to put an X before the number (e.g., X543) or add an H after the number, like 543H. Thus,

\[X543={{543}_{16}}=543H=5\times {{16}^{2}}+4\times {{16}^{1}}+3\times {{16}^{0}}=\left( 5 \right)\left( 256 \right)+\left( 4 \right)\left( 16 \right)+\left( 3 \right)\left( 1 \right)=1347\]

The following shows examples of hexadecimal numbers (without the preceding X):


To have a better feeling for the values of these numbers, we calculate their decimal equivalents. You notice that if we do not use the preceding X, it is not clear if numbers such as 48 and 312 are decimal or hexadecimal, and these are quite different.

The decimal magnitudes of hexadecimal numbers are calculated in the same way shown earlier for 543 in both cases of having 10 or 16 as for base. Because 160 = 1, we refrain from its repetition and use 1 for the multiplier of the rightmost (least significant) digit.

\[\begin{align}& X48=4\times {{16}^{1}}+8\times 1=72 \\& X312=3\times {{16}^{2}}+1\times {{16}^{1}}+2\times 1=786 \\& XA9=10\times {{16}^{1}}+9\times 1=169 \\& XABCD=10\times {{16}^{3}}+11\times {{16}^{2}}+12\times {{16}^{1}}+13\times 1=43,981 \\& XC3=12\times {{16}^{1}}+3\times 1=195 \\& X2AA=2\times {{16}^{2}}+10\times {{16}^{1}}+10\times 1=682 \\& X12DF=1\times {{16}^{3}}+2\times {{16}^{2}}+13\times {{16}^{1}}+15\times 1=4831 \\\end{align}\]

Also, notice the following

$\begin{align}& X99=9\times {{16}^{1}}+9\times 1=153 \\& XFF=15\times {{16}^{1}}+15\times 1=255 \\& X100=1\times {{16}^{2}}+0\times {{16}^{1}}+0\times 1=256 \\& XFF+1=X100 \\\end{align}$

Note that equivalent to 99, 999, and similar decimal numbers (i.e., those figures before the number of digits increases) in the hexadecimal system we have FF, FFF, and so on. Thus,

$\begin{align}& X1000-1=XFFF \\& XFFF+1=X10’000 \\\end{align}$

(Note that it is not necessary to write X1 instead of 1 because there is no ambiguity.)

Example 1

Find the decimal equivalent of XABCD0.


In the same way that in the decimal number system a number like 1230 is 10× the number 123, we can use the analogy to say the number XABCD0 is 16× the number XABCD. The decimal equivalent of the latter has already been found to be 43,981. Thus, for the decimal value of XABCD0, we have

$XABCD0=\left( 16 \right)\left( 43,981 \right)=703,696$

The reverse process of finding the hexadecimal expression of decimal numbers can be done by successive divisions by 16. The remainder of a division determines the digit for the number. Consider, for example, the small figure 23. Dividing this figure by 16, we can write

\[\begin{align}& \begin{matrix}23=1\times 16+7 & \leftarrow & \text{the first digit from right is 7} \\\end{matrix} \\& \begin{matrix}{} & \swarrow & {} \\\end{matrix} \\& \begin{matrix}1=0\times 16+1 & \leftarrow & \text{the second digit from right is 1} \\\end{matrix} \\& \begin{matrix}{} & \uparrow & {} \\\end{matrix} \\& \begin{matrix}{} & Stop\text{ dividing when this quotient has reaced 0} & {} \\\end{matrix} \\\end{align}\]

The arrows on the left show the procedure, and the arrows on the right show the answer. The answer is 17, as defined by the numbers 7 and 1 denoted by arrows. The oblique arrow starting from 1 on the first row toward the second row denotes the transfer of the quotient to a new line for the continuation of the same process of dividing by 16. The vertical arrow shows that when the quotient becomes 0 the process should stop.

For this small number, only one division is sufficient (the last one is not really necessary). But for larger numbers, the dividing process must be repeated a number of times until no more division is possible (or no extra results are obtained). The following examples show the same procedure for larger numbers. It is not necessary to show the arrows. Here they help to understand.

Example 2

Find the hexadecimal representation of decimal 52,778.


$\begin{align}& 52,778=3298\times 16+10\to A \\& 3298=206\times 16+2\to 2 \\& 206=12\times 16+14\to E \\& 12=0\times 16+12\to C \\\end{align}$

The answer is XCE2A.

Binary Number System

The binary number system has only two base numbers, 0 and 1. The reason for developing such a number system is its applicability to many physical processes that have two states, and thus a binary number is sufficient to describe them. These physical states can be in the form of

• On and off

• True and false

• High and low

• Yes and no

• Positive and negative

depending on the application. For example, for switches and switching devices in an electrical circuit, the on-off defines the state of one switch. This can be the basis of storing data, which can consist of the many switches or devices where each one assumes one of the two states at a time.

A number in the binary system, thus, can have only 0’s and 1’s because there is no other symbol. Note that in the same way that in the decimal system the number after 9 (the last number element) is 10, in the binary system the number after 1 is 10. The following lines show a few examples of some decimal numbers when written in the binary system. A subscript b or 2 is used to indicate that a number is binary.

$\begin{align}& 0=0 \\& 1=1 \\& 2={{10}_{b}} \\& 3={{11}_{b}} \\& 4={{100}_{b}} \\& 10={{1010}_{b}} \\& 11={{1011}_{b}} \\& 12={{1100}_{b}} \\& 15={{1111}_{b}} \\& 16={{10000}_{b}} \\\end{align}$

Before we learn how to find the binary equivalent of a number, note that in the same way that 10 + 1 = 11, in the given binary numbers the same thing can be verified:


and after 1111b (the last four digits binary number) is 10000 (the first five- digit number), in the same way, that after 9999 in decimal numbers we have 10000.

The decimal equivalent of any binary number can be found by the same procedure we have used earlier for the number 543. We use the above figures to verify that they really are equivalent to each other:

$\begin{align}& {{10}_{b}}=1\times {{2}^{1}}+0\times {{2}^{0}}=2+0=2 \\& {{11}_{b}}=1\times {{2}^{1}}+1\times {{2}^{0}}=2+1=3 \\& {{1111}_{b}}=1\times {{2}^{3}}+1\times {{2}^{2}}+1\times {{2}^{1}}+1\times {{2}^{0}}=8+4+2+1=15 \\& {{10000}_{b}}=1\times {{2}^{4}}+0\times {{2}^{3}}+0\times {{2}^{2}}+0\times {{2}^{1}}+0\times {{2}^{0}}=16+0+0+0+0=16 \\\end{align}$

Example 3

Find the decimal number for the binary 1011010110b.


For clarity, it is convenient to show the number as 10, 1101, 0110b, that is, separating every four digits from the right. This number has 10 digits.

$1\times {{2}^{9}}+0\times {{2}^{8}}+1\times {{2}^{7}}+1\times {{2}^{6}}+0\times {{2}^{5}}+1\times {{2}^{4}}+0\times {{2}^{3}}+1\times {{2}^{2}}+1\times {{2}^{1}}+0\times {{2}^{0}}=512+128+64+16+4+2=726$

But, note that it is not necessary to write the multipliers because they are either 1 or 0. Moreover, 0 multiplied by any number results in 0; hence, it is not necessary to write. The above mathematical line can be reduced to


To find the binary number equivalent of a decimal number, use the following procedure:

1. Divide the number by 2 and write the quotient and the remainder.

2. If the remainder is 0, the rightmost digit is zero; otherwise, it is 1.

3. Substitute the quotient for the number and repeat the division by 2.

4. If the remainder is 0, the second digit is 0; otherwise, it is 1.

5. Continue the same procedure until the quotient reaches 0.

Octal Number System

Another number system that is more utilized in the industry is the octal numbers, having number 8 as the base. The rules for conversion from octal to decimal and vice versa are the same as the other number systems. Numbers 0 to 7 are used for the eight main symbols. Thus, the positive numbers start from 0 and are

0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 …

Again, each octal number must be followed by a subscript 8 to indicate its base. The following examples show the calculation of the decimal equivalent of an octal number and the octal equivalent of a decimal number.

Example 4

Find the decimal value of 20128.


${{2012}_{8}}=2\times {{8}^{3}}+0\times {{8}^{2}}+1\times {{8}^{1}}+2\times 1=512+8+2=1034$

Example 5

Find the octal representation of number 7777.


\[\begin{align}& \begin{matrix}7777=972\times 8+1 & \to & 1 & \text{first digital from right} \\\end{matrix} \\& \begin{matrix}972=121\times 8+4 & \to & 4 & \text{second digit} \\\end{matrix} \\& \begin{matrix}121=15\times 8+1 & \to & 1 & \text{third digit} \\\end{matrix} \\& \begin{matrix}15=1\times 8+7 & \to & 7 & \text{fourth digit} \\\end{matrix} \\& \begin{matrix}1=0\times 8+1 & \to & 1 & \text{fifth digit} \\\end{matrix} \\\end{align}\]

The octal number is 171418.

Conversion between Binary and Hexadecimal Numbers

The fact that hexadecimal numbers are based on 16, and 16 is the fourth power of 2 makes the conversion between hexadecimal and binary numbers easy. Consider a single digit hexadecimal number. The values expressed by this digit are between 0 and 15. Now consider the numbers that may be represented by four digits in a binary number. Again, they are between 0 and 15. All these numbers are compared together below (the prefix X for hexadecimal numbers is omitted for simplicity).

$\begin{align}& {{0000}_{b}}=0 \\& {{0001}_{b}}=1 \\& {{0010}_{b}}=2 \\& {{0011}_{b}}=3 \\& {{0100}_{b}}=4 \\& {{0101}_{b}}=5 \\& {{0110}_{b}}=6 \\& {{0111}_{b}}=7 \\& {{1000}_{b}}=8 \\& {{1001}_{b}}=9 \\& {{1010}_{b}}=A \\& {{1011}_{b}}=B \\& {{1100}_{b}}=C \\& {{1101}_{b}}=D \\& {{1110}_{b}}=E \\& {{1111}_{b}}=F \\\end{align}$

The above equivalence can be directly carried to all other digits of a hexadecimal number and the set of four digits of a binary number. The following are some examples.

\[\begin{align}& \text{X123 = 0001,0010,0011b } \\& \text{X47A = 0100,0111,101}{{\text{0}}_{\text{b }}} \\& \text{XBCD1 = 1011,1100,1101,000}{{\text{1}}_{\text{b}}}\text{ } \\& \text{XA00F5 = 1010,0000,0000,1111,010}{{\text{1}}_{\text{b}}}\text{ } \\& \text{1111,1100,0011,0000,1110 = XFC30E } \\& \text{0000,1001,0000,1111 = X90F} \\\end{align}\]

Note that in the last number the leftmost 0 is not shown in the hexadecimal number, whereas in a binary number it is very common to have 0’s on the left, as you will see in the next section.

Example 6

Find the hexagonal equivalent of 1001, 1010,1100,1111,1000, 0001.


Each digit can be calculated or looked up in the preceding list. Thus,

\[\text{1001,1010,1100,1111,1000,0001 = 9ACF8}{{\text{1}}_{\text{16}}}\]

Direct Conversion between Binary and Octal Numbers

Direct conversion between octal and binary numbers is possible. A binary number can be divided into groups of three, each of which corresponds to one digit of its associated octal number. Only the first 8 out of 16 in the preceding list correspond to octal numbers, and the 0 on the left must be omitted so that there are only three digits for each binary number. Some examples are as follows.

\[\begin{align}& \text{000,101,000,100b = 50}{{\text{4}}_{\text{8}}}\text{ } \\& \text{000,101,111,100b = 57}{{\text{4}}_{\text{8}}}\text{ } \\& \text{001,001,111,101b = 117}{{\text{5}}_{\text{8}}}\text{ } \\& \text{010,111,110,000b = 276}{{\text{0}}_{\text{8}}}\text{ } \\& \text{100,111,110,000b = 476}{{\text{0}}_{\text{8}}}\text{ } \\& \text{111,101,011,001b = 753}{{\text{1}}_{\text{8}}} \\\end{align}\]

As said before, the 0’s on the left side of a binary number do not need to be included in the converted number.