Hexadecimal

Binary is counting in base-2, as discussed in the textbook section Binary. Hexadecimal is counting in base-16.

You can break down a number into parts based on it position. Notice how we use the subscript like X2 to indicate the number is written in base-2, or X10 for a base-10 number.

The symbols we use to count by powers are all values less than base:

  • Base 2 uses two symbols (0,1) to count.
  • Base 10 uses ten symbols (0,1,2,3,4,5,6,7,8,9) to count.
  • Base 16 uses symbols sixteen symbols: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f.

Base 10 Example

153410 = 1 x 103 + 5 x 10 2 + 3 x 10 1 + 4 x10 0 = 1000 + 500+ 3 + 4

Base 2 Example

11012 = 1x 23 + 1x 22 + 0x 21+ 1x 20 = 8 + 4+ 1 = 1410

Base 16 Examples

153416 = 1 x 16 3 + 5 x 162 + 3 x16 1 + 4x 160= 542810 

beef16 = b x 16 3 + e x 162 + e x16 1 + fx 160=  11 x 16 3 + 14 x 162 + 14 x16 1 + 15 x 160= = 4887910

8 bits is a byte

A single hex digit can represent any four-digit binary value, or 4 bits: 

00002 = 016, 00012 = 116, …, 11102 = e16, 11112 = f16

Since a byte is eight bits, it needs two hex digits:

1f16 is the byte 000111112

This makes hex a convenient way to write colors, like we discuss when we talk about RGB values.

Hex digitBinaryDecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115
This table shows equivalent hex, binary, and decimal values

Pixels Represented in Hexadecimal

A pixel may be specified by the RGB Color Model (Red, Green and Blue). An 8-bit (one byte) number represents the amount of each color, where 0 means nothing, and 255 means all the intensity the monitor can provide. We have 256 possible values for red, green and blue. We usually write these colors in hex or as a sequence of decimal numbers. We discuss pixels in the chapter section Measurement Units.

Example

(42, 46, 163) is the (R,G,B) color also written as #2a2ea3 where 4210 = 2a16, 4610 = 2e16, and 16310 = a316

You need not write a subscript for RGB colors since it’s clear in context which base we’re talking about!