# 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 X_{2} to indicate the number is written in base-2, or X_{10} 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**

1534_{10} = 1 x 10^{3 } + 5 x 10^{ 2} + 3 x 10^{ 1} + 4 x10^{ 0 } = 1000 + 500+ 30+ 4

**Base 2 Example**

1101_{2 }= 1x 2^{3} + 1x 2^{2} + 0x 2^{1}+ 1x 2^{0} = 8 + 4+ 1 = 13_{10}

**Base 16 Example**s

1534_{16} = 1 x 16^{ 3 } + 5 x 16^{2} + 3 x16 ^{1} + 4x 16^{0}= 5428_{10}

beef_{16} = b x 16^{ 3 } + e x 16^{2} + e x16 ^{1} + fx 16^{0}=
11 x 16^{ 3 } + 14 x 16^{2} + 14 x16 ^{1} + 15 x 16^{0}= = 48879_{10}

**8 bits is a byte**

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

0000_{2} = 0_{16}, 0001_{2} = 1_{16}, …, 1110_{2} = e_{16}, 1111_{2} = f_{16}

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

1f_{16} is the byte 00011111_{2}

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

Hex digit | Binary | Decimal |

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 |

A | 1010 | 10 |

B | 1011 | 11 |

C | 1100 | 12 |

D | 1101 | 13 |

E | 1110 | 14 |

F | 1111 | 15 |

# 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 42_{10} = 2a_{16}, 46_{10} = 2e_{16}, and 163_{10} = a3_{16}

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