Skip to content

Computer Science · Ch 2 — Encoding Schemes and Number System

Applications of Hexadecimal Number System

2.2.5

Applications of Hexadecimal Number System

Where does hexadecimal actually get used? Two everyday places: memory addresses and web colours. Both are cases where humans must read long binary values, and hexadecimal makes them manageable.

1. Memory addresses

Main memory is made up of memory locations, and each location has a unique address. The size of a memory address is usually 16-bit or 32-bit. To access a 16-bit memory address directly, a programmer would have to work with 16 binary bits — hard to read, hard to remember, easy to get wrong. To simplify address representation, hexadecimal and octal numbers are used instead.

Consider the 16-bit memory address:

Binary       :  [PII:card]        (16 bits — unwieldy)
Hexadecimal  :  C0F1                    (4 symbols — easy to remember)
Octal        :  140361                  (6 digits)

The hexadecimal form maps each group of 4 bits to one symbol (1100 → C, 0000 → 0, 1111 → F, 0001 → 1), shrinking sixteen bits to four characters.

2. Colours on a webpage

Hexadecimal numbers also describe colours on webpages. Every colour is composed of the three primary colours red, green and blue — RGB for short. In most colour maps, each colour is chosen from a palette of about 16 million colours. Representing one colour therefore requires 24 bits:

8 bits for the Red component
8 bits for the Green component
8 bits for the Blue component
─────────────────────────────
24 bits per colour

Remembering a 24-bit binary colour code is impractical, so colour codes are written in hexadecimal for compactness. For example, pure RED is:

Binary       :  11111111, 00000000, 00000000
Hexadecimal  :  (FF, 00, 00)

— full intensity red (FF = 255), zero green, zero blue.

Some common colours in all three notations:

ColourDecimal (R,G,B)BinaryHexadecimal
Black(0, 0, 0)(00000000, 00000000, 00000000)(00, 00, 00)
Table 2.7Colour codes in decimal, binary and hexadecimal numbers
Colour NameDecimalBinaryHexadecimal
Black(0,0,0)(00000000,00000000,00000000)(00,00,00)
White(255,255,255)(11111111,11111111,11111111)(FF,FF,FF)
Yellow(255,255,0)(11111111,11111111,00000000)(FF,FF,00)