Featured image

Table of Contents Link to heading

Hexadecimal (Hex) Numbering Link to heading

a convenient way to represent binary values.

1 hex = 1 nibble = 4 bits = 1/2 byte

Data is often stored using word sizes that are multiples of 4 bits.

Hexadecimal is a base 16 system and uses the numbers 0 to 9 and the letters A/a to F/f.

Use Cases Link to heading

Three basic usages of hex include HTML colour codes, MAC addresses, and IPv6 addresses.

Other possible usage include:

  • Extensively used in assembly programming languages and in machine code.
  • Often used to refer to memory addresses.
  • Can be used during the debugging stage of writing a computer program.
  • Used to represent numbers stored in a CPU’s registers or in main memory.

All Zeros versus All Ones Link to heading

Given that 8 bits (a byte) is a common binary grouping, binary 00000000 to 11111111 represent the hexadecimal range 00 to FF.

Representing Hexadecimals Link to heading

Leading zeros are always displayed to complete the 8-bit representation. For example, the binary value 0000 1010 represents 0A in hexadecimal.

Hexadecimal numbers are often represented by a value preceded by 0x (e.g, 0x73 and 0x0A) to distinguish between decimal and hexadecimal values in documentation.

Hexadecimal may also be represented using a subscript 16 or by using the hex number followed by an H (e.g., 73H and 0AH).

Hexadecimal Conversions Link to heading

Conversion Table Link to heading

Decimal Binary Hexadecimal
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

Binary to Hexadecimal Link to heading

Break the binary value into groups of 4 and convert every group to one hex digit (add zeros to the left end of the binary number to create groups of four if needed).

0011 10112 = 3B16

  1. 00112 = 316
  2. 10112 = B16

Hexadecimal to Binary Link to heading

Take each hexadecimal digit and find the binary equivalent.

3B16 = 0011 10112

  1. 316 = 00112
  2. B16 = 10112

Decimal to Hexadecimal Link to heading

Decimal :right_arrow: binary :right_arrow: hexadecimal

5910 = 0011 10112 = 3B16

  1. 00112 = 316
  2. 10112 = B16

Hexadecimal to Decimal Link to heading

Binary Detour Link to heading

Hexadecimal :right_arrow: binary :right_arrow: decimal

3B16 = 0011 10112 = 5910

Positional Notation Link to heading

Since there are 16 digits, each position represents a power of 16.

2A4F16 = 2×163 + 10×162 + 4×161 + 15×160 = 1083110

Doubling Link to heading

Take each leftmost value (converted to decimal), multiplied by 16 and added to the next value.

2A4F16

  1. 0×16 + 2 = 2
  2. 2×16 + 10 = 42
  3. 42×16 + 4 = 676
  4. 676×16 + 15 = 1083110