Hexadecimal notation is just a way of describing integers in a different base other than the usual decimal base that we’re familiar with.

Hexadecimal notation uses base 16 which means that as opposed to the standard 10 digits that we are used to; we’re going to use a system in which there are 16 digits.

Those digits are represented by the number 0 through 9 along with the six letters A through F as indicated in the table below.

 Decimal Number 4-bit Binary Number Hexadecimal Number 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F

Each of those hexadecimal digits corresponds to a different value in the range of 0 to 15.

So, the hex digits 0 through 9 corresponds to the values 0 through 9 and then the hex digit A corresponds to 10, the hex digit B corresponds to 11 and so on up through the hex digit F which corresponds to the value 15.

Hex digits are also very convenient because there’s a one to one correspondence between each hex digit and sequence of 4 bits which are sometimes also called a nibble.

4 bits is exactly half a byte which is 8 bits and so a sequence of 4 bits is sometimes also referred to as a nibble.

As you can see from the table above, the hex digit 0 corresponds to the nibble 0000 and so on up through the hex digit F which corresponds to the nibble 1111.

These correspondences aren’t arbitrary. What you’ll see is that each hex digit corresponding to a particular nibble corresponds to the value of that nibble if you view it as a binary integer.

Just as an example, if we look at the hex digit F that corresponds to the nibble 1111 and in binary notation the value 1111 corresponds to:

1111 = 2^3 + 2^2 + 2^1 + 2^0 = 15

Which in fact is the value that corresponds to the hex digit F.

## How to convert hexadecimal to decimal notation

For example, lets convert hex ABC to a decimal:

C = 12 * (16 ^ 0) 12
B = 11 * (16 ^ 1) 176
A = 10 * (16 ^ 2) 2560

2560 + 176 + 12 = 274810 decimal

We can also represent the hex ABC in terms of binary representation. And it’s very easy to do that because each hex digit corresponds to a nibble.

Hex ABC = [1010 1011 1100].

And again that 12-bit binary corresponds to the value 2748 if we view that 12-bit number as a binary number.

## ASCII Representation

Ultimately everything in a computer is represented as bits and ASCII representation is very often used to represent English letter characters.

In ASCII representation each character is represented using one byte or 8 bits or equivalently two hex digits.

Here is a table indicating the correspondences between characters in the English alphabet along with other characters as well as their corresponding ASCII equivalent.

 ASCII Hex Symbol 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 A B C D E F NUL SOH STX ETX EOT ENQ ACK BEL BS TAB LF VT FF CR SO SI
 ASCII Hex Symbol 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
 ASCII Hex Symbol 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F (space) ! " # \$ % & ' ( ) * + , - . /
 ASCII Hex Symbol 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
 ASCII Hex Symbol 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F @ A B C D E F G H I J K L M N O
 ASCII Hex Symbol 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F P Q R S T U V W X Y Z [ \ ] ^ _
 ASCII Hex Symbol 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F ` a b c d e f g h i j k l m n o
 ASCII Hex Symbol 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F p q r s t u v w x y z { | } ~ 

You can see that alongside every character the table includes both their ASCII representation written in hex as well as in decimal.

You can check that all the numbers line up by performing a calculation just like we did earlier.

For example;

“1” = 0x31 = 0011 0001

“F” = 0x46 = 0100 0110

If we look at the character “1” which is the numeral one, that has value hex 31 in the ASCII representation.

That means that if you have a file and somewhere in that file you have the character “1”, that would actually be recorded in your computer as the hex value 31.

At the lower level it would be represented as a sequence of bits (00110001).

That is to say the nibble corresponding to 3 and the nibble corresponding to 1.

The key thing I want to point out here is that the character 1 is not the same thing as the number 1.

The character 1 is just a character and it’s arbitrary been assigned the ASCII value of hex 31 in ASCII representation.

And if you have a character 1 in a file it’s not stored as a single bit 1, it’s stored as the byte (00110001).

And similarly, for the rest of the characters are stored in the same way.

## Data representation

The question is, how do we store the value hex 1F to a file. There are two ways we could go about doing this.

The first possibility is what I call native hex.

And in this case, we store the value exactly as the sequence of bits that it represents. For example, we could store the value hex 1F to a file as (0001 1111).

The problem with that is that if we then try to view that file using a standard text editor, we’ll get a none printable character.

And if you go back and look at the ASCII table, you’ll see that the hex 1F corresponds to some unprintable character not a regular character in the alphabet or a numeral or punctuation.

That’s okay if all you’re doing is reading from that file from a program but it’s inconvenient if we’re trying to look at the file or manipulate the file by hand.

The second possibility is to store the hex value 1F as the ASCII characters 1F.

If we do that then recall that every ASCII character is represented using one byte so, what we now have is something stored using 2 bytes rather than one.

That is using 16 bits rather than 8 bits.

If we store the ASCII characters 1F to a file then what we’ll end up actually storing in terms of bits is (0011 0001 0100 0110).

Which you obtain by looking up the character 1 and F in the ASCII table and writing out their corresponding representations.

Now if we view this file using a text editor or from the command line, we see what we expect.

We see the characters 1F.

If we read it from a program, the program is going to see a sequence of 16 bits.

We just need to be careful and tell the program to convert that sequence of 16 bits into the hex value 1F.

## How to convert hex to text

For example, convert hex (6b 69 66 61 6e 67 61) to text.

Step 1. Group the hex values string into groups of two characters.

Group = [6b 69 66 61 6e 67 61].

Step 2. Read the corresponding ASCII character with each hex pair.

ASCII characters = [k, I, f, a, n, g, a].

Thus, hex (6b 69 66 61 6e 67 61) to text is (kifanga).

Use the above hex to text converter to easily translate your hexadecimal values to their ASCII equivalents.

Recommended Tools