Using Hexadecimal Numbers

Which of the following two lines below is easier for you to read and remember?

01001100 01111010 00001110 01010011

4C 7A 0E 53

The second line, which is definitely easier to read and remember, is written in the hexadecimal numbering system. It contains exactly the same information as the binary data in the first line. Computers operate using binary data, but it far easier for humans to read binary data that doesn't look like an endless string of 1's and 0's. Thus hexadecimal (base 16) notation is used. The computer doesn't operate in hex, but it is far easier for us to look at data and commands if the binary information is written in hex format.

The hexadecimal number system has 16 numbers. It uses the familiar 0-9, followed by six more numbers, which have been rather boringly called A-F. The table below lists numbers in their hexadecimal, decimal, and 4-bit binary formats.

Hex

decimal

4-bit binary

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

A

10

1010

B

11

1011

C

12

1100

D

13

1101

E

14

1110

F

15

1111

 

In this course, the only conversions we will do between hexadecimal and decimal will be for 0-F (hex). We will not learn to do more complex conversions involving multiple hex digits. We will learn hex-binary conversions, however.

From the table, you can see that a single hex number can be represented by 4 bits, which means that any 8-bit byte can be represented by 2 hex numbers. This conversion ability is what made it so much easier to read the hex data, rather than the binary data, at the very beginning of this page. To convert a binary number to hex , simply break it into two 4-bit parts and convert each part into a hex number.

Thus, for example:

01100111 (binary)

becomes 0110 0111

which is 6 7 (hex)

Here's another example: 10111111 (binary)

becomes 1011 1111

which is B F (hex)

Conversion in the other direction is simple -- just look up the table value for each hex number and write them as one continuous 8-bit binary number.

For example:

7A (hex)

becomes 0111 1010

which is 01111010 (binary)

 

Here's another hex-binary conversion:

2C (hex)

becomes 0010 1100

which is 00101100 (binary)

Practice converting back and forth with your own numbers. If your two conversions come back to the same starting point, your conversion method is correct.