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

DecimalBinaryHexadecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

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 ➡ binary ➡ hexadecimal

5910 = 0011 10112 = 3B16

  1. 00112 = 316
  2. 10112 = B16

Hexadecimal to Decimal Link to heading

Binary Detour Link to heading

Hexadecimal ➡ binary ➡ 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