How can a screen in Leeds turn a string of ones and zeroes into a flag?
A school in Leeds wants to put a tiny French flag on its display. The screen gets a string of ones and zeroes. How does it know which colour to draw first, and when to start a new row?
A key tells you what each code means. Here, zero zero means white, zero one means blue, one zero means red, and one one means black. Each tiny picture element is a pixel. Dimensions give the width and height in pixels. Colour depth gives the bits per pixel, here two.
The flag is three pixels wide and two pixels high. Watch the order: blue, white, red across the top. Now jump back to the left and read blue, white, red across the bottom. That path through the pixels is called the scan order.
You've just read the rightmost pixel of the top row. The image has another row below it, and you read every row from left to right. Which pixel should you read next? Pick an answer.
Read the top row. Blue becomes zero one, white becomes zero zero, and red becomes one zero. Repeat for the bottom row, which has the same colours. Now join the codes in that order, keeping all the zeroes. Turning pixels into a bit stream is encoding.
Try a pattern that's two pixels wide and two pixels high. The top row is white then black. The bottom row is black then white. Use zero zero for white and one one for black. Pick the bit stream that reads both rows from left to right.
Now go backwards from a new stream of bits. Start at the left and split it into pairs because each pixel takes two bits. The image is three pixels wide, so take three pairs for the top row. Wrap back to the left for the next three pairs.
Use the key in reverse. The first three codes are all one one, so draw three black pixels across the top. Return to the left one row down. Zero zero, one one, zero zero give you white, black, white. The rows line up to make a tiny letter T.
A width of three can tempt you to cut the stream after three bits. See how that leaves a single bit without its partner at the end of the row? Count three complete pixel codes instead. Here, those three pixels use six bits.
For this exam question, count only the pixel data. Eight times four gives thirty-two pixels. At two bits per pixel, that's sixty-four bits. Divide by eight to get eight bytes. If you double just the width, just the height or just the colour depth, the pixel data size doubles.