We can pack four bits (binary digits) into one hexadecimal digit because 16 is a power of two (16 = 24). So, a group of four bits represents a value between 0 and 15, and one hex digit also represents values from 0-15 (using 0-9 and A-F). This makes it easier to translate between binary and hex than between other bases.
You can create a table like this whenever you need one.
binary | hex |
00002 | 016 |
00012 | 116 |
00102 | 216 |
00112 | 316 |
01002 | 416 |
01012 | 516 |
01102 | 616 |
01112 | 716 |
10002 | 816 |
10012 | 916 |
10102 | A16 |
10112 | B16 |
11002 | C16 |
11012 | D16 |
11102 | E16 |
11112 | F16 |
To translate a binary numeral (like 11010111012) to hexadecimal, start by splitting it into groups of four bits, from right-to-left (like this: 11 0101 1101).
Then determine the value of each group and write the corresponding hex digit (look it up on the table at right).
For example: 112 = 316, 01012 = 516, and 1101 = D16. So, 1101011101_2 = 35\text{D}_{16}.
To translate a hex numeral (like 4E116) to binary, write each hex digit as a group of four bits (even if the binary representation doesn't need all four digits).
For example: 416 = 01002, E16 = 11102, and 1 = 00012. So, 4\text{E}1_{16} = 010011100001_{2} or just 10011100001_{2} because we can drop the leading zero once the digits are all in their places.
Computers have several ways of representing colors depending on whether they are intended for controlling three-color RGB (red, green, blue) screen display, four-color CMYK (cyan, magenta, yellow, black) printing, or other purposes. On a computer screen, each pixel—each dot that makes up the picture on the screen—is assigned an RGB color defined by the intensity of red, green, and blue in that color. These three color intensities each range from 0 to 255 (one byte is used for each of the three colors), which is 00 to FF in hex notation.
If (R, G, B) = (128, 0, 255), the color is purple: some red and a lot of blue, but no green at all. If all three colors are as bright as possible (all are 255), we see white; if they are as dark as possible (all are 0), we see black. Instead of writing (255, 255, 255) for white and (128, 0, 255) for purple, we often use hex notation: FFFFFF and 8000FF. And this color is red 255, green 127, and blue 0, which is FF7F00 in hex.