4-Color Bitmap Example
[rev. 11/5/2006]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This is more challenging than the monochrome bitmap example and takes twice as much storage space, because we need to define a 2-bit palette. (We need at least 2 bits per pixel in order to represent 4 different colors.)

Let us agree to the following color map:
   00 = white (same as RGB value FF FF FF hex)
   01 = blue (same as RGB value 00 00 FF hex)
   10 = red (same as RGB value FF 00 00 hex)
   11 = black (same as RGB value 00 00 00 hex)

 

 

Uncompressed data in binary (12 x 36 pixels x 2 bits per pixel = 864 bits):

101010101000010100101010101010101010101010101000111100001100000011111100
101010101000010100101010101010101010101010101000110011001100001100000011
101010101000010100101010101010101010101010101000110000111100000011111100
101010101000010100101010101010101010101010101000000000000000000000000000
000000000000010100000000000000000000000000000000001111111100001100000011
010101010101010101010101010101010101010101010100001100000011001100110011
010101010101010101010101010101010101010101010100001111111100001100110011
000000000000010100000000000000000000000000000000001100001111000011001100
101010101000010100101010101010101010101010101000000000110000000000000000
101010101000010100101010101010101010101010101000000011001100001100000011
101010101000010100101010101010101010101010101000001111111111000011111100
101010101000010100101010101010101010101010101000001100000011000000110000

You may be able to see some of the Norwegian flag in the pattern of 1’s and 0’s. If you squint really hard, you may be able to make out the word “NORWAY” in the 1’s on the right side.

Next, separate the binary data into groups of 4 bits:

1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 1111 0000 1100 0000 1111 1100
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 1100 1100 1100 0011 0000 0011
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 1100 0011 1100 0000 1111 1100
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0101 0000 0000 0000 0000 0000 0000 0000 0000 0011 1111 1100 0011 0000 0011
0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0100 0011 0000 0011 0011 0011 0011
0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0100 0011 1111 1100 0011 0011 0011
0000 0000 0000 0101 0000 0000 0000 0000 0000 0000 0000 0000 0011 0000 1111 0000 1100 1100
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 0000 0011 0000 0000 0000 0000
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 0000 1100 1100 0011 0000 0011
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 0011 1111 1111 0000 1111 1100
1010 1010 1000 0101 0010 1010 1010 1010 1010 1010 1010 1000 0011 0000 0011 0000 0011 0000

 

Now, translate into hex (108 bytes total):

AA 85 2A AA AA A8 F0 C0 FC
AA 85 2A AA AA A8 CC C3 03
AA 85 2A AA AA A8 C3 C0 FC
AA 85 2A AA AA A8 00 00 00
00  05  00  00  00  00  3F C3 03
55  55  55  55  55  54  30 33 33
55  55  55  55  55  54  3F C3 33
00  05  00  00  00  00  30 F0 CC
AA 85 2A AA AA A8 03 00 00
AA 85 2A AA AA A8 03 C3 03
AA 85 2A AA AA A8 3F F0 FC
AA 85 2A AA AA A8 30 30 30

 

 

Remember that the protocol may require additional bytes for the header, color map, and terminator of the file.