Kahibaro
Discord Login Register

2.4 Hexadecimal Basics

Understanding Hexadecimal

Hexadecimal, often shortened to “hex,” is a way to write numbers using base 16 instead of base 10. In everyday life you use base 10, which has ten digits from 0 to 9. Hexadecimal has sixteen digits. This makes hex very useful in computing, especially when you work with binary, because it gives a compact and readable way to represent long binary patterns.

In this chapter you will see what the hex digits are, how to read and write hex numbers, and why hex is convenient when dealing with networking and low level data. You will connect it later to binary conversions and data representation, so the goal here is to understand the system itself and how to use it in simple conversions.

Hexadecimal Digits

Hexadecimal needs sixteen symbols. The first ten are the same as decimal. For the extra six values, the letters A to F are used.

Hex digitDecimal value
00
11
22
33
44
55
66
77
88
99
A10
B11
C12
D13
E14
F15

A single hexadecimal digit can therefore represent any value from 0 to 15. When you see A in hex, you should think “ten.” When you see F, you should think “fifteen.”

Place Values in Hex

Hexadecimal is a positional number system. This means the position of each digit matters, just like in decimal.

In decimal, from right to left, the places are powers of 10:

In hexadecimal, from right to left, the places are powers of 16:

This pattern leads to a general rule for the value of a hex number.

Rule: Value of a hexadecimal number
For a hex number with digits $d_{n-1} d_{n-2} \dots d_1 d_0$ (each $d$ is 0 to 15), its decimal value is
$$\text{value} = \sum_{i=0}^{n-1} d_i \cdot 16^i$$
The rightmost digit has $i = 0$.

For example, take the hex number 2A. Here:

So the total decimal value is $32 + 10 = 42$.

Writing and Reading Hex Numbers

In many technical texts hexadecimal numbers are marked clearly so that you do not confuse them with decimal. There are several common notations:

Notation styleExampleMeaning
Suffix h2AhHex 2A
Prefix 0x0x2AHex 2A
Prefix 0X0X2AHex 2A

You may also see hex numbers written without any prefix or suffix when the context is clear, for example inside an IPv6 address or a MAC address. In this chapter you can assume that any value that contains letters A to F is hexadecimal.

When you read hex numbers, it helps to translate each digit to its decimal value in your head, then remember which place value it has. For a beginner it is useful to say it aloud. For example, 3F in hex can be read as “three times sixteen plus fifteen.”

Manual Conversion from Hex to Decimal

You will have a separate chapter that covers number conversions in general. Here you will see the specific method for hex to decimal, because it is central to understanding hex itself.

To convert a hexadecimal number to decimal, follow these steps:

  1. Write down the hex number and label the positions, starting from 0 at the right.
  2. Convert each hex digit to its decimal value.
  3. Multiply each value by $16^{\text{position}}$.
  4. Add the results.

For example, convert 0x1C to decimal.

You can set this up in a small table to keep track:

Hex digitPositionDecimal valuePower of 16Contribution
111$16^1 = 16$$1 \times 16=16$
C012$16^0 = 1$$12 \times 1=12$

Total decimal value is $16 + 12 = 28$.

Here is another example with three digits, 0x2F4.

Once you know the first few powers of 16, this process becomes much faster.

Powers of 16 to Remember

You do not need to memorize many powers of 16 to work comfortably with hex. The most useful ones fit into a small table.

ExponentPower of 16Decimal value
$16^0$11
$16^1$1616
$16^2$16 × 16256
$16^3$16 × 16 × 164096
$16^4$16⁴65536

With this table, you can quickly work out many common hex values. For example, hex 100 is

Ranges Representable with Hex Digits

Because each hex digit can hold 16 values, you can easily compute the range of values that can be stored with a certain number of hex digits.

For one hex digit you have values from 0 to 15.
For two hex digits you have $16^2 = 256$ possible combinations, from 00 to FF.
For three hex digits you have $16^3 = 4096$ combinations, from 000 to FFF.

The maximum value with $n$ hex digits is always one less than $16^n$.

Rule: Maximum value for $n$ hex digits
With $n$ hexadecimal digits, the maximum integer value is
$$\text{max} = 16^n - 1$$
For example, with 2 digits the maximum is $16^2 - 1 = 256 - 1 = 255$, which is FF in hex.

This rule shows up a lot in networking, for example when you look at limits on fields inside protocol headers.

Grouping and Formatting Hex Values

In practice, long hex sequences are split into groups to make them easier to read. You will see several grouping styles in networking:

Each pair of hex digits forms a natural unit, which you will later learn to relate to a byte. For now the key idea is that 2 hex digits are usually read together as one chunk of information.

When you see many hex digits next to each other, try to break them into groups of two from the right. This will help you read and work with them more easily.

Where Hexadecimal Appears in Networking

Hexadecimal is common throughout networking because it makes long binary values shorter and more readable, while still mapping cleanly to the underlying bits. You will see hex in several places later in the course, such as:

You do not need to understand those networking uses yet. At this stage it is enough to recognize that when you see values with A to F in them, you are most likely looking at hexadecimal, and to be comfortable reading and converting those numbers.

Practicing with Simple Hex Values

To get used to hexadecimal, it is useful to become fluent with small hex numbers, especially the range from 0 to FF. These are the values that appear most often when data and addresses are shown in hex form.

Here are some simple examples that you can practice in both directions in your head:

HexDecimal
00
99
A10
F15
1016
1F31
2032
2A42
3C60
7F127
FF255

If you can look at values like 7F and FF and quickly recall their decimal meanings, later parts of networking, such as reading address fields and packet dumps, will feel much more natural.

In later chapters you will connect hexadecimal directly to binary and learn faster methods for converting between the two. For now, a clear understanding of what hex is, how place values work, and how to perform basic hex to decimal conversion is enough.

Views: 49

Comments

Please login to add a comment.

Don't have an account? Register now!