ViewWiki

Lesson 3 of 4

Colour and hexadecimal.

About 25 minutes · 6 practice questions

A pixel is three numbers: how many colours so many levels give, bits per pixel, counting in base 16, web colour codes, and light that adds up.

Step 1 of 6 · Three numbers a pixel

Step 1 of 6

Three numbers a pixel

Each pixel on a screen is three tiny lights, red, green and blue, so close together that the eye sees one colour. The computer stores each light’s strength, a level between off and full. A pixel’s colour is a combination of three levels, so with LL⁠ levels per channel there are

L×L×L=L3L \times L \times L = L^3⁠

colours. The board shows the number of colours, but not the number of levels. Work it out.

To the question

Step 2 of 6

Bits per pixel

Look inside is open: each pixel in the magnifier has split into three lights, and each light has risen into a column as tall as its level. A whole pixel takes the bits of all three channels together. In true colour that is 3×8=243 \times 8 = 24⁠ bits, three bytes, which is why it is also called “24-bit colour”.

To the question

Step 3 of 6

Base 16

A byte written in base 2 is eight digits, long and easy to get wrong. So programmers write bytes in base 16, hexadecimal. It has sixteen digits: 00⁠ to 99⁠, then A, B, C, D, E and F for 1010⁠ to 1515⁠. The place values are 11⁠, 1616⁠, 256256⁠ and so on.

The trick is that 16=2416 = 2^4⁠: each hexadecimal digit is exactly four bits, so a byte is exactly two digits. 1111 111121111\,1111_2⁠ becomes FF16\mathrm{FF}_{16}⁠, and 0100 110120100\,1101_2⁠ becomes 4D16\mathrm{4D}_{16}⁠, four bits per digit.

To the question

Step 4 of 6

Colour codes

Web pages and drawing programs write a colour as three bytes in base 16, after a # sign, always in the order red, green, blue: #RRGGBB, where RR are the two digits of red, GG of green and BB of blue.

#FFFFFF is white, #000000 is black, and #FF0000 full red.

To the question

Step 5 of 6

Reading a code

To read a pair of digits, multiply the left one by 1616⁠ and add the right one. Try it on the colour code of sea green, #3CB371.

To the question

Step 6 of 6

Light that adds up

The columns in the magnifier are light, not paint. When the screen lights several of them together the eye receives them all, and the light adds up: the more you light, the brighter the colour. Three full lights look white. What do you see when only two of them are on?

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Calculate

The board shows that at this depth a pixel can show 4096 colours. How many levels can each channel, red, green or blue, take?

To the experiment

Practice · Reach the target

Change Bits per channel so that a whole pixel, all three of its channels, takes exactly 12 bits, a byte and a half, and press Check.

To the experiment

Practice · Calculate

In base 16 the digits are 0 to 9 and then A to F, which are 1010⁠ to 1515⁠. What is FF16\mathrm{FF}_{16}⁠ in base ten?

To the experiment

Practice · Choose

Which colour is #FF8000?

To the experiment

Practice · Calculate

In the colour code #3CB371 the two green digits are B3. How strong is the green, in base ten?

To the experiment

Practice · Choose

A pixel stores red 255, green 255 and blue 0. Which colour do you see on the screen?