The hexadecimal number system has sixteen characters; it is used primarily as a compact way of displaying or writing binary numbers because it is very easy to convert between binary and hexadecimal. As you are probably aware, long binary numbers are difficult to read and write because it is easy to drop or transpose a bit. Since computers and microprocessors understand only 1s and 0s, it is necessary to use these digits when you program in “machine language.” Imagine writing a sixteen bit instruction for a microprocessor system in 1s and 0s. It is much more efficient to use hexadecimal

The hexadecimal number system has a base of sixteen; that is, it is composed of 16 numeric and alphabetic characters. Most digital systems process binary data in groups that are multiples of four bits, making the hexadecimal number very convenient because each hexadecimal digit represents a 4-bit binary number (as listed in Table 2–3).


Ten numeric digits and six alphabetic characters make up the hexadecimal number system. The use of letters A, B, C, D, E, and F to represent numbers may seem strange at first, but keep in mind that any number system is only a set of sequential symbols. If you understand what quantities these symbols represent, then the form of the symbols themselves is less important once you get accustomed to using them. We will use the subscript 16 to designate hexadecimal numbers to avoid confusion with decimal numbers. Sometimes you may see an “h” following a hexadecimal number.

Counting in Hexadecimal

How do you count in hexadecimal once you get to F? Simply start over with another column and continue as follows:

.... , E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 2C, 2D, 2E, 2F, 30, 31, ....

With two hexadecimal digits, you can count up to FF(16), which is decimal 255. To count beyond this, three hexadecimal digits are needed. For instance, 100(16) is decimal 256, 101(16) is decimal 257, and so forth. The maximum 3-digit hexadecimal number is FFF(16), or decimal 4095. The maximum 4-digit hexadecimal number is FFFF(16), which is decimal 65,535.

Binary-to-Hexadecimal Conversion

Converting a binary number to hexadecimal is a straightforward procedure. Simply break the binary number into 4-bit groups, starting at the right-most bit and replace each 4-bit group with the equivalent hexadecimal symbol.

EXAMPLE 1

Convert the following binary numbers to hexadecimal: 

(a) 1100101001010111 

(b) 111111000101101001

Solution:




Two zeros have been added in part (b) to complete a 4-bit group at the left.

Hexadecimal-to-Binary Conversion

To convert from a hexadecimal number to a binary number, reverse the process and replace each hexadecimal symbol with the appropriate four bits

EXAMPLE 2

Determine the binary numbers for the following hexadecimal numbers:
(a) 10A4
(16) 

(b) CF8E(16) 

(c) 9742(16)

Solution:


In part (a), the MSB is understood to have three zeros preceding it, thus forming a 4-bit group.


 

 Hexadecimal-to-Decimal Conversion

One way to find the decimal equivalent of a hexadecimal number is to first convert the hexadecimal number to binary and then convert from binary to decimal.

EXAMPLE 2

Convert the following hexadecimal numbers to decimal: 

(a) 1C(16) 

(b) A85(16) 

Solution: 

Remember, convert the hexadecimal number to binary first, then to decimal.


Another way to convert a hexadecimal number to its decimal equivalent is to multiply the decimal value of each hexadecimal digit by its weight and then take the sum of these products. The weights of a hexadecimal number are increasing powers of 16 (from right to left). For a 4-digit hexadecimal number, the weights are:


EXAMPLE 2

Convert the following hexadecimal numbers to decimal: 

(a) E5(16) 

(b) B2F8(16) 

Solution: 

Recall from Table 2–3 that letters A through F represent decimal numbers 10 through 15, respectively.


Decimal-to-Hexadecimal Conversion

Repeated division of a decimal number by 16 will produce the equivalent hexadecimal number, formed by the remainders of the divisions. The first remainder produced is the least significant digit (LSD). Each successive division by 16 yields a remainder that becomes a digit in the equivalent hexadecimal number.

EXAMPLE 2

Convert the decimal number 650 to hexadecimal by repeated division by 16.

Solution: