Hexadecimal

Author

Clayton Cafiero

Published

2026-10-01

Introduction to hexadecimal

Computers represent and process information using binary values, which are patterns of 0s and 1s. Binary is great for hardware, but it is not very convenient for humans. Writing long strings of bits like 1010110110010101 is slow, error-prone, and hard to read. Every operation in a computer works with binary values, but engineers and programmers need a format that is easier to visualize and reason about.

Accordingly, we often use hexadecimal notation, or simply “hex”. Hexadecimal is a base-16 system of representation. In decimal we only have 10 digits (0 through 9), therefore, to represent decimal 10 through 15 we use the letters A through F. Thus, Hex is a compact way to write values in a way that still has a strong connection to binary, since 16 = 2^4. Each hexadecimal digit represents exactly four binary bits. This means that one byte, which is eight bits, can be represented by just two hex digits.

Take this 16-bit binary pattern as an example: 1010 1101 0110 0011.

It is difficult to tell what this number means just by looking at it. If we divide the bits into groups of four, we can translate each group into a single hexadecimal digit.

binary 1010 1101 0110 0011
binary, grouped 1010 \mid 1101 \mid 0110 \mid 0011
hex, grouped A \mid D \mid 6 \mid 3
hex 0xAD63

So 0xAD63 represents the same binary pattern, but it is shorter and easier to read. Notice that we use a prefix 0x to indicate that this is a hexadecimal number.

Note

Remember: Hexadecimal is a base-16 number system. It uses digits 0–9 for values zero through nine and letters A–F for values ten through fifteen. Each hexadecimal digit maps to exactly four bits (also called one nibble).

decimal binary hex
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

Reading and writing hexadecimal

In programming and computer engineering, hexadecimal numbers are usually written with the prefix 0x to avoid confusion with decimal numbers. For example, 0xFF means “the hexadecimal value FF”, which is the same as decimal 255.

hex binary decimal meaning
0x0 0000 0 All bits clear
0x1 0001 1 Only bit 0 set
0xA 1010 10 Second and fourth bit set
0xF 1111 15 All four bits set

When there are multiple hex digits, each digit corresponds to four binary bits.

For example: 0x2A \rightarrow 0010 1010 in binary. 0xFF \rightarrow 1111 1111 in binary. 0xFFFF \rightarrow 1111 1111 1111 1111 (which can be used as a full 16-bit word mask).

Converting between binary and hexadecimal

It is straightforward to convert between binary and hexadecimal because of the relationship between the two systems.

  1. Start from the binary number.
  2. Separate the bits into groups of four, moving from right to left.
  3. Replace each group with its matching hexadecimal digit.

Example: 1101 0100 1111 \rightarrow 0xD4F (work this out on your own to be sure you understand the process).

You can reverse the process to go from hexadecimal back to binary by replacing each hex digit with its 4-bit binary equivalent.

Tip

When you are looking at memory addresses or register values, hexadecimal is much easier to interpret than binary. Each byte lines up neatly to two hex digits, and each word lines up to four or eight digits depending on the architecture.

Hexadecimal in memory and machine code

Most computer systems show memory addresses and instruction encodings in hexadecimal. Most binary values are too long to read comfortably, and decimal numbers do not match the natural power-of-two boundaries used by hardware.

A 32-bit address written in binary might look like this: 00000000101011010110001101010100

In hexadecimal, the same address is written as: 0x0AD6354

The hexadecimal form is much shorter, and patterns in data are easier to recognize. When you read memory dumps or instruction encodings, the hex representation makes it simple to see which bits belong to which field.

For example, in an ARM instruction, different groups of bits represent the opcode, the source registers, and the destination register. Seeing the instruction in hex allows you to quickly mask or extract those bit fields.

© 2026 Clayton Cafiero.

No generative AI was used in writing this material. This was written the old-fashioned way.