Warning
This chapter is still in development
Warning
This chapter hasn’t been written yet, but in the meantime there is a lesson plan that covers the material available from the NZACDITT site. The content of this chapter will mainly support this lesson plan.
Note
For teachers
This chapter supports the “Data representation” option of the NZ achievement standard 2.44. For this standard, students need to choose at least two different types of data (e.g. text and colours) for achieved, and then for merit they need to ensure that for each of those two types of data, they have chosen at least two different representations (e.g. 8-bit text and 16-bit text) and they should discuss the implications of using each of the different representations (as a key idea is that there are different ways of representing the same types of data, where the different ways tend to have different strengths and weaknesses).
Currently this chapter has 3 different types of data; text, numbers, and colours. Colour representations build on number representations, so to be able to do that section students will need to have done the first part of the numbers section. So all the possible pathways for students wanting to gain merit for the standard are (assuming minimum requirements) - Full binary numbers section + colours section - Full binary numbers section + text section
The last option above may be best for a lot of students. Less able students may be very confused by the details towards the end of the binary numbers section, which are particularly abstract and not as “real” to students as colours and text are. The later part of the binary number section could also be particularly difficult and meaningless for students who have never programmed before, as it somewhat builds on that context so would come across as even more abstract for students in this category.
It is important also for teachers to understand what is NOT relevant to this standard. The key idea here is to be looking at how computers represent data. Computers always must represent data using patterns of bits (where each bit can be in one of two states); the reasons for this are discussed in the introduction chapter. If the representation you are looking at doesn’t involve representing the data as patterns of bits, it isn’t relevant to the standards.
One example of a potential misconception of what is relevant is to use hexadecimal. Hexadecimal is NOT a representation using bits; it is a shorthand notation used to make patterns of bits more readable to a human. Computers do not use hexadecimal (or octal) at all for representing data. If students use hexadecimal, it should include demonstrating an understanding of the binary that it represents, and not show the misconception that computers store hexadecimal.
Also, comparing decimal numbers and binary numbers would not be relevant to the standard. While the binary numbers are using patterns of bits, the decimal numbers are not. Both representations being compared must be ones that a computer can store data with.
Computers are machines that do stuff with information. They let you view, listen, create, and edit information in documents, images, videos, sound, spreadsheets and databases. They let you play games in simulated worlds that don’t really exist except as information inside the computer’s memory and displayed on the screen. They let you compute and calculate with numerical information; they let you send and receive information over networks. Fundamental to all of this is that the computer has to represent that information in some way inside the computer’s memory.
To make computers easier to build and keep them reliable, everything is represented using just two values. You may have seen these two values represented as 0 and 1, but on a computer they are represented by anything that can be in two states. For example, in memory a high or low voltage is used to store each 0 or 1. On a magnetic disk it’s stored with... magnetism (whether a tiny spot on the disk is magnetised north or south).
When we write patterns of bits on paper, we normally use “0” for one of the states, and “1” for the other state. If a piece of computer memory had the following bits: “low”, “low”, “high”, “low”, “high”, “high”, “high”, “high”, “low”, “high”, “low”, “low”, we could allocate “0” to “low”, and “1” to high” and write this sequence down as 001011110100. While this notation is used extensively, and you may sometimes hear bits being referred to as being “0’s and 1’s”, it is important to remember that a computer does not store 0’s and 1’s; it has no way of doing this. As we said above, they have to store them using physical mechanisms such as high and low voltage, north or south polarity, and light or dark materials.
Jargon buster: The use of the two digits 0 and 1 is so common that some of the best known computer jargon is used for them. Since there are only two digits, the system is called binary. The short word for a “binary digit” is made by taking the first two letters and the last letter — a bit is just a digit that can have two values.
Every file you save, every picture you make, every download, is just a whole lot of bits. This chapter is about some of the different ways that computers use to code different kinds of information in patterns of these bits.
Note
For teachers
This section is not directly relevant to the standard, although we do recommend students work through it as it provides a good introduction to the concept of bits, emphasising the idea that computers represent data as patterns of bits, rather than this topic being all about binary numbers, which is a common misconception.
You may have heard of Braille, a “written” language used for those with visual impairment so that they can read by touch rather than sight. Each character in braille is represented with a cell of 6 dots. Each dot can either be raised or not raised. Different numbers and letters can be made by using different patterns of raised and not raised dots.
When working through the material in this section, a good way to draw braille on paper without having to actually make raised dots is to draw a rectangle with 6 small circles in it, and to colour in the circles that are raised, and not colour in the ones that aren’t raised.
So, how many different patterns can be made using the 6 dots in a Braille character?
With 2 dots, there are 4 patterns. [shall we just draw these rather than describe them as text?}
First dot NOT raised, second dot NOT raised First dot NOT raised, second dot raised First dot raised, second dot NOT raised First dot raised, second dot raised
And with 3 dots there are 8 patterns First dot NOT raised, second dot NOT raised, third dot NOT raised First dot NOT raised, second dot NOT raised, third dot raised First dot NOT raised, second dot raised, third dot NOT raised First dot NOT raised, second dot raised, third dot raised First dot raised, second dot NOT raised, third dot NOT raised First dot raised, second dot NOT raised, third dot raised First dot raised, second dot raised, third dot NOT raised First dot raised, second dot raised, third dot raised
You may have noticed that there are twice as many patterns with 3 dots as there are with 2 dots. It turns out that every time you add an extra dot, that gives twice as many patterns (why?), so with 4 dots there are 16 patterns, 5 dots has 32 patterns, and 6 dots has 64 patterns
So, 64 patterns can be made in Braille.
Braille is a scheme for representing english characters using bits. Patterns of 6 bits represent a character, and the bits are physically represented using “raised” and “not raised” dots.
No, I meant should I say anything more linking it to representing using bits concepts?
As you saw above 64 unique patterns can be made using braille.
Count how many different upper-case letters, lower-case letters, numbers, and symbols that you could insert into a text editor using your keyboard. (Don’t forget to count both the symbols that share the number keys, and the symbols to the side that are for punctuation!). The collective name for these is characters. e.g. a, D, 1, h, 6, *, ], ~ are all characters.
Would 6 dots (which can represent 64 patterns) be enough to represent all these characters? If you counted correctly, you should find that there were more than 64 characters! How many bits would you need to be able to represent all the characters you counted on your keyboard?
It turns out that 7 dots is enough as this gives 128 possible patterns, and this is exactly what ASCII did. ASCII is one of the main systems that computers use to represent text.
ASCII assigned a different pattern of bits to each of the characters, along with a few other “control” characters that you don’t need to worry about yet (or perhaps already know!). For reasons that you will understand later, each pattern in ASCII is actually 8 bits long rather than 7 bits. However, the first bit in each pattern is always a 0, meaning there are still only 128 possible patterns.
You should be able to see that the letter c (lower-case) in the table has the pattern “01100011”. The letter o has the pattern “01101111”. What pattern does the letter m have?
Computers can represent pieces of text with sequences of these patterns, much like Braille does. For example, the word “computers” (all lower-case) would be 01100011 01101111 01101101 01110000 01110101 01110100 01100101 01110010 01110011
How would you represent the word “science” in ASCII? What about “Wellington” (note that it starts with an upper-case “W”)? How would you represent the number “358” in ASCII? What about the sentence “Hello, how are you?” (look for the comma, question mark, and space characters in the ASCII table).
If you ONLY wanted to represent the 26 letters of the alphabet, and weren’t worried about upper-case or lower-case, you could get away with using just 5 bits, which allows for up to 32 different patterns. Have a look at the last 5 bits of each of the 26 lower-case letters in ASCII. Do any of the 26 lower-case letters have the same last 5 bits? Have a look at the 26 upper-case letters. Do any of the upper-case letters have the same last 5 bits?
You may have noticed that none of the lower-case letters have the same last 5 bits, but they do have the same last 5 bits as their corresponding upper-case letter! For example, a = 1100001 and A = 1000001, they both have 00001 as their last 5 bits. As another example, s = 1110011 and S = 1010011, they both have 10011 as their last 5 bits.
An easy way to allocate patterns in this 5 bit system would be to just use the last 5 bits for each character in the ASCII table. Therefore A would be 00001, b would be 00010, c would be 00011, etc.
The word “water” would be 10111 00001 10111 10100 10010
English text can easily be represented using ASCII, but what about languages such as Chinese where there are thousands of different characters? The 128 patterns (or even 256 if the first bit was allowed to be 0 or 1) aren’t nearly enough to represent the Chinese language!
Another representation called Unicode uses 16 bits per character rather than the 7 bits per character in ASCII. As you saw earlier, every extra bit that is added doubles the number of patterns possible. This means that there are 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 2^16 = 65536 patterns that can be represented with Unicode. This is enough to assign a unique pattern of bits to all characters in all languages [ ? ]. ..Apparently not, according to wikipedia. Even this wasn’t enough for all languages. They started with just 16 bits, but now they have had to extend it to allow 32 bits!! which I didn’t know before today...The current standard has over 110,000 characters, and both UTF-8 and UTF-16 allow up to 4 bytes. UCS-2, which is what I thought unicode was, just had the 16 bits, but it is now obsolete.’ .. HRN:. Ah. I suspected thta wa the case cause chiese has 80000 + chars.
The unicode table is far too big to display in this book, but
For achieved, students should show the binary representations of some (personalised) numbers. For merit, students should do and explain some of the personalised activities in the “computers representing numbers in practice”
We have decided to approach this section by starting with number systems. While this may appear “scary” because of the math, most students should be quite familiar with it as it is first introduced very early in primary school in the form of recognising that numbers are made up of the “ones”, “tens”, “hundreds”, etc, and is further built on until eventually in high school they learn about the exponent notation, i.e. 541 = 5x10^2 + 4x10^1 + 1x10^0. As explained in this section, binary numbers are a base 2 number system, rather than the base 10 number system we are all familiar with. The idea of number systems provides a good stepping stone into binary numbers
We are assuming that students already know about base 10 number systems, including the exponent notation. The initial information in this section on them is only intended to trigger recall, rather than actually teaching them the concept.
Less mathematically able students who are really struggling with the number systems stuff should be able to skip over it, and instead go directly to making binary numbers in the interactive.
You may remember learning about how our number system is in base 10, and the value of each digit in a number depends on its place in the number.
Each place value in a number is 10 times bigger than the previous place value, i.e. there are the “ones”, the “tens”, the “hundreds”, the “thousands” the “ten thousands”, the “hundred thousands”, the “millions”, etc. Each of which is 10 times bigger than the last. In addition, there are 10 different digits (0,1,2,3,4,5,6,7,8,9) that can be at each of those place values.
As you went further through school, you may have encountered different ways of expressing numbers using “expanded form”. Assume you want to write the number 90328 in expanded form. Early in school you might have written 90328 = 90000 + 300 + 20 + 8 Then a bit later you may have learnt that you could write 90328 = (9 x 10000) + (0 x 1000) + (3 x 100) + (2 x 10) + (8 x 1) And then in high school you probably learnt about exponents, and could write it as 90328 = (9 x 10^4) + (0 x 10^3) + (3 x 10^2) + (2 x 10^1) + (8 x 10^0)
As you learned in the introduction, computers can only store information using bits, which only have 2 possible states. This means that they cannot represent base 10 numbers using digits 0 to 9, the way we write down numbers; instead, they use a base 2 number system called binary.
Because binary is base 2, there are only 2 possible digits (0 and 1), as opposed to the 10 in our standard number system, and each place value is 2 times bigger than the previous place (in contrast to our base 10 number system where each place is 10 times bigger)
The interactive below illustrates how this binary number system works. Have a play around with it to see what patterns you can see. The decimal (base 10) representation for the binary number currently shown is given by the interactive.
To ensure you are understanding correctly how to use the interactive, verify that when you enter the binary number 101101 it shows that the decimal representation is 45, that when you enter 100000 it shows that the decimal representation is 32, and when you enter 001010 it shows the decimal representation is 10.
This interactive makes it very easy to convert a binary number back to decimal, as it does the calculations for you. You cannot use it to convert a decimal number to binary, although once you have figured out this conversion, you can double check it by putting the binary you worked out into the interactive, and ensuring it gives the decimal number you started with.
Can you figure out the binary representation for 23? What about 4, 0, and 32? Check all your answers using the interactive to verify they are correct.
You have probably noticed from the interactive that when set to 1, the leftmost bit (the “most significant bit”) adds 32 to the total, the next adds 16, and then the rest add 8, 4, 2, and 1 respectively. When set to 0, a bit does not add anything to the total. So the idea is to make numbers by adding some or all of 32, 16, 8, 4, 2, and 1 together, and each of those numbers can only be included once.
Rather than just using trial and error to figure out what a decimal number is in binary, can you figure out a systematic approach? Have a look at what 100000 is in binary. What about 011111? Is it possible to make a number over 32 if the most significant bit is set to a 0? Why? And what about 001000 and 000111? Can you see a pattern that would lead to a systematic way of converting decimal numbers to binary? Hint: start with deciding the leftmost bit, and then work along to the right, bit by bit.
can we point them to another online resource for it? eg http://www.wikihow.com/Convert-from-Decimal-to-Binary, (the second method), or https://www.khanacademy.org/science/computer-science/v/binary-numbersCan you figure out a systematic approach to counting in binary? i.e. start with the number 0, then increment it to 1, then 2, then 3, etc, all the way up to the highest number that can be made with the 6 bits. Hint: Think about how you add 1 to a number in base 10. e.g. how do you work out 7 + 1, 38 + 1, 19 + 1, 99 + 1, 230899999 + 1, etc? Can you apply that same idea to binary?
Using your new knowledge of the binary number system, can you figure out a way to count to higher than 10 using your 10 fingers? What is the highest number you can represent using your 10 fingers? What if you included your 10 toes as well (so you have 20 fingers and toes to count with).
Computers use represent numbers is t In programming languages, there are two commonly used kinds of numbers; integers and floating point numbers. Integers are what you might know as whole numbers that can be positive or negative, whereas floating point numbers can have a decimal point in them, and can also be positive or negative. In this section we are just going to focus on integers, as representing floating point numbers is a bit more difficult to understand!
You may have noticed that the binary number representation in the previous section only allowed us to represent positive numbers. In practice, we will want to be able to represent negative numbers as well (such as when the amount of money earned goes to a negative amount!). In our normal representation of base 10 numbers, we represent negative numbers by putting a minus sign in front of the number. In a computer, we don’t have minus signs, but we can do it by having one extra bit, called a sign bit to represent the minus sign. We usually make the leftmost bit be the sign bit. When the sign bit is set to “0”, that means the number is positive; when the sign bit is set to “1”, the number is negative (just as if there were a minus sign in front of it). For example, if we wanted to represent the number 41 using 6 bits (like above) along with an additional 7th bit that is the sign bit, assuming the sign bit is first, we would represent it by 0101001. The first bit is a 0, meaning the number is positive, then the remaining 6 bits give 41, meaning the number is +41. If we wanted to make -59, this would be 1111011. The first bit is a 1, meaning the number is negative, and then the remaining 6 bits give 59, meaning the number is -59. ..(1 is for negative sign, 0 for positive: http://en.wikipedia.org/wiki/Sign_bit
Using 7 bits like described above (one for the sign, and 6 for the actual number), what would be the representations for 1, -1, -8, 34, -37, -88, and 102? .. Why not do it in the reverse direction so that they are understanding what the bits represent, and it doesn’t depend on being able to convert decimal to binary. They need to be able to convert decimal to binary for the achieved part of the standard though. Why would they be attempting thie merit component if they couldn’t do that?
1 is 00000001 -1 is 10000001 -8 is 10001000 34 is 00100010 -37 is 10100101 -88 is 11011000 102 is 01100110
It actually isn’t this simple. Assuming we have an 8 bit number where the first bit is the sign bit, and the other 7 bits represent the actual value of the number, what is the representation for 0? Is it 10000000 or 0000000, i.e. is it +0 or -0? This turns out to be a problem, we don’t want more than one representation of 0! As a result of this problem number representations in practice aren’t actually as simple as what this chapter has implied! If you are curious at a common way computers represent numbers to get around this problem, take a look at the wikipedia page on Two’s Complement (Warning: it is quite technical!)
http://en.wikipedia.org/wiki/Two%27s_complement
Another issue is that because of the way computer memory is constructed, memory is most commonly used in chunks of 8 bits or 32 bits (or even 64 bits) at a time.
That means that if the computer is representing an integer as a binary number with a sign bit, it will commonly use 32 bits, where the first bit is the sign bit, and the other 31 bits represent the value of the number.
In the interactive, you could represent 64 different numbers (0 up to 63) because there were only 6 bits. In a computer that uses 32 bits for a number, how many different numbers could it represent? What’s the largest number it could represent? Remember that every bit you add doubles how many numbers you can make. If you double 64 another 25 times (so that it is up to 31 bits), i.e. 128, 256, 512, 1024, 2048.... with an end result of 2147483648. This means that there 2,147,483,648 numbers that can be represented with 31 bits, the highest of which is 2,147,483,647. This number is just over 2 billion. With the 32nd bit, the sign bit, this means that the number can be positive or negative. This is called a signed 32 bit integer. So with the signed 32 bit integer, you can represent any number between -2,147,483,647 and +2,147,483,647.
There is also such thing as a 32 bit *unsigned* integer. This does not have a signed bit, and the 32nd bit is included as part of the value. As a result, it can represent twice as many positive numbers (but no negative numbers), as the 32 bit signed integer above. This would be 4,294,967,296 different numbers, with 4,294,967,295 being the highest.
How many people are in the world? (If you aren’t sure, go look it up on google!) Would a 32 bit integer like described above be large enough to store a different ID number for each person in the world?
In some languages such as C, there are a few other choices for integer size. If the amount of bits your computer has to store its data in is VERY limited, you might not want to reserve 32 bits for a number if it is never going to be over 100. Two other integer sizes are 8 bits, and 16 bits. And for larger numbers, there are 64 bit integers. All of these can be signed or unsigned.
So when you are storing values on a computer with very limited space, you need to be careful to pick a suitable kind of integer that has enough space, but isn’t wasting space. You also need to think about whether or not a number could potentially be negative.
Think of a few different examples for different sized integers (both signed and unsigned ones) of a piece of data that you could store in that sized integer. For example, the age of a person could be stored in an 8 bit unsigned integer (people can’t be a negative age!), and the number of students in your school could be stored in an 8 bit or 16 bit integer, depending on how big your school is! What other examples can you think of?
What are some examples of numbers you could NOT represent using any of these integers?
This section assumes that you understand binary numbers. If you are confused by binary numbers still, you should go back to the binary numbers section and work through the material there again until you understand it. The first part of this section is possible to understand without understanding binary numbers, although in order to actually use the material for assessment purposes, you will need to understand binary numbers, as the key idea is representing colours using bits, and the bits in colours are decided based on numbers.
In primary school or art class you may have gotten to mix different colours of paint or dye together in order to make new colours. This was probably very helpful if the exact colour you wanted was not present in your palette, in addition to just being fun to experiment with!
If you mixed red and blue, you would get purple. If you mixed yellow and blue, you would get green. If you mixed red and yellow, you would get orange. If you mixed an even amount of the 3 primary colours; blue, yellow, and red together, you would get black. By mixing together various amounts of the three primary colours, along with white and black, you can make many different colours.
The below interactive allows you to play around with this, in case you have forgotten, or just like mixing colours.
The exact colours in the above interactive are actually cyan, magenta, and yellow. You may have heard of this set of colours before; they are the colours of the ink in a coloured printer. By mixing different amounts of them together, a printer can create many different colours.
Computers also rely on mixing colours, except they go about it in quite a different way. Starting on a dark computer screen, each pixel has 3 tiny lights; one red, one green, and one blue. By increasing and decreasing the amount of light coming out of each of these 3 lights, all the different colours can be made.
http://www.cosc.canterbury.ac.nz/mukundan/cogr/RGB.html
How do you get shades of purple, yellow, orange, and pink? What happens when you have the same amount of each colour? How do you get black? How do you get white?
So now, how can computers represent each possible colour using bits? You may have noticed in the above interactive that for each of red, green, and blue, there are 256 different positions the slider can be in (don’t forget to include setting the slider to 0). From the numbers section, you may remember that to get 256 different possibilities, you need 8 bits. So for example, to represent the current value of the red slider, you would need 8 bits (2^8 = 2x2x2x2x2x2x2x2 = 256)
Because there are three primary colours, each of which has 256 different possible positions we need 24 bits in order to have enough possible bit patterns to represent all the possible colours that this scheme can represent. (3 x 8 = 24).
If you calculate 2^24 (i.e. the number of bit patterns you can get with 24 bits), and 256*256*256 (i.e. the number of possible colours that can be represented using the above interactive), you will find that the result of these two calculations are the same; 16,777,216. This means that there are 16,777,216 different possible colours that can be represented using this scheme.
I like the idea of boxes and different explanations for different learning styles.
So now that we know we’ll need 24 bits to represent all the possible colours that can be made from the scheme in the interactive, how can we assign colours to bit patterns?
A sensible way is to use 3 binary numbers that represent the amount of each of red, green, and blue in the pixel. In order to do this, you can simply convert the decimal values on the interactive that specify how much of each of the primary colours is making up the resulting colour into binary, and put them side by side to make a full pattern of 24 bits. Because consistency is important in order for a computer to make sense of the bit pattern, the binary number for red should be put first, followed by green, and then finally blue.
As an example, say you have the colour that has red = 145, green = 50, and blue = 123 (It is a shade of purple; set the sliders to those values in the interactive above). You need to convert each of the 3 numbers into binary, using 8 bits for each. You can either do this by hand if you are confident with binary numbers, use the binary number interactive in the above section, or use a binary piano. You should get red = 10010001 You should get green = 00110010 You should get blue = 01111011 This can be written as 100100010011001001111011, which is the bit pattern for representing that shade of purple. Note that there are no spaces between the 3 numbers, as this is a pattern of bits rather than actually being 3 binary numbers, and computers don’t have any such concept of a space between bit patterns anyway. Everything must be a 0 or a 1. Also note that all leading and trailing 0’s on each of the components are kept. Make sure you work through this example yourself, to understand how it works.
As long as the computer knows this is a colour, it will know that the first 8 bits specify the amount of red, the next 8 bits specify the amount of green, and the last 8 bits specify the amount of blue. The computer won’t actually convert the number into decimal, as it knows how to interpret the binary directly. You don’t need to understand how it does this though, this is to do with how computers actually process bits!
24 bit colour is very commonly used in raw image formats, such as [TODO]. These formats assign colours to bit patterns in the same way described above.
The 6 characters that make up a colour code are hexadecimal digits, from a base 16 number system. The advantage of hexadecimal is that it is particularly easy to converet from binary to hexadecimal or from hexadecimal to binary. There are 16 hexadecimal digits (0 to F), so each different digit can be assigned to a different pattern of 4 bits.
0000 -> 0 0001 -> 1 0010 -> 2 0011 -> 3 0100 -> 4 0101 -> 5 0110 -> 6 0111 -> 7 1000 -> 8 1001 -> 9 1010 -> A 1011 -> B 1100 -> C 1101 -> D 1110 -> E 1111 -> F From the patterns that are equivalent to the numbers 0 - 9, the corresponding decimal digit is used. For the patterns that are equivalent to the numbers 10 - 15, the letters A - F are used In the 24 bit colour example above, the 24 bit pattern was:
This can be broken up into 4’s 1001 0001 0011 0010 0111 1011 And then using the table above, you can assign a hexadecimal digit to each of the 4 bit patterns. This gives 91327B. This is the hexadecimal code for this colour! .. Note, this is actually a rather bad example. I might make a better one. The hexadecimal notation is extremly useful for people to read or write, as it is much easier to type 6 characters rather than 24 1’s and 0’s when specifying a colour!
Understanding how these hexadecimal colour codes are derived also allows you to change them slightly without having to refer back the colour table, when the colour isn’t exactly the one you want. Remember that in the 24 bit color code, the first 8 bits specify the amount of red (so this is the first 2 digits of the hexadecimal code), the next 8 bits specify the amount of green (the next 2 digits of the hexadecimal code), and the last 8 bits specify the amount of blue (the last 2 digits of the hexadecimal code). To increase the amount of any one of these colours, you can change the appropriate hexadecimal letters.
What if we were to use less than 24 bits to represent each colour, i.e. each slider didn’t have as many possible positions it could be in?
Another colour scheme which is sometimes used (although becoming less common these days) is 8 bit colour. 8 bit colour uses 3 bits to specify the amount of red (8 possible values), 3 bits to specify the amount of green (again 8 possible values), and 2 bits to specify the amount of blue (4 possible values). This gives a total of 8 bits (hence the name), which can be used to make 256 different bit patterns, and thus can represent 256 different colours. .. I think there needs to be a transition through to the interactive. You have an alternative transition later, but you could pull those ideas to this point. Or maybe this paragraph was just a temporary introduction - there seems to be some repetition.
Using this scheme to represent all the pixels of an image takes one third of the number of bits required for 24-bit colour, but it is much less good at showing smooth changes of colours or subtle shades, because there are only 256 possible colors for each pixel.
Suppose the computer has an image represented using 24-bit color. To change the image to use 8-bit colour (which will take less space), the computer has to go through each pixel in the image and choose the 8-bit colour that is closest to the original pixel colour.
The interactive below has an image where you can click on a pixel,and it will show you what the 24 bit colour is for that pixel. Your job is to then use the 8 bit colour sliders to try and match the colour as near as you can. Do this for a few pixels.
If the image was using 8 bit color instead of 24 bit colour, the 8 bit colours you are selecting for the pixels are the ones that would have to be used in the image. You will have probably found that the nearest 8 bit colour to the 24 bit colour can be quite different!
So, given that we can’t represent as many colours, why would we actually want to use this colour scheme at all?
An image represented using 24 bit colour would have 24 bits per pixel. In 600 * 800 pixel image, this would contain 600 * 800 = 480,000 pixels,and thus 480,000 * 24 bits = 11,520,000 bits. If you do the rest of the math, this works out to around 1.44 MB’s.
If space is very limited, we can use less bits to represent each colour. One system for this is 8 bit color. 8 bit colour is not used much anymore, although it can still be helpful in situations such as accessing a computer desktop remotely on a slow internet connection, as the image of the desktop can instead be sent using 8 bit colour instead of 24 bit colour. Even though this may cause the desktop to appear a bit strangely, it doesn’t stop you from getting whatever it was you needed to get done, done. There are also other situations where colour doesn’t matter at all, for example diagrams, and black and white photocopy images.
Converting an 8 bit colour into a bit pattern is very similar to before. Remember that this time we are using 3 bits for red, 3 bits for green, and 2 bits for blue. If for example the colour you have chosen has the values red = 2, green = 6, and blue = 1 (you can make this colour using the above interactive, you would do the following. For red and green, you want to use 3 bits to represent the number. So for red, 2 would be 010 For blue, 6 would be 110 For green, you want to use just 2 bits to represent the number. So for green, 1 would be 01. You can then merge these together in the order of red, green, and blue to get the bit pattern for the 8 bit colour. In this case, it would be 01011001.
When the computer goes to read this 8 bit number, it knows that the first 3 bits specify the amount of red, the next 3 specify the amount of green, and the last 2 specify the amount of blue.
Now that you know how the 24 bit and 8 bit colour schemes work and how to represent them using bits, what are the implications of this in practice?
The interactive below has a series of images that you can select, where it shows both the 24 bit and the 8 bit images side by side.
Which cases is the change in quality most noticeable? In which is it not? In which would you actually care about the colours in the image? In which situations is colour actually not necessary (i.e. we are fine with black and white)?
One other interesting thing to think about is whether or not we’d want more than 24 bit colour. It turns out that the human eye can only differentiate around 10 million colours, so the 16 million provided by 24 bit colour is already beyond what our eyes can distinguish.
[explain where the material above has oversimplified things, and if there are any well-known concepts or techniques that have been deliberately left out because they are too complex for this age group. This may include things that require advanced maths, advanced programming, or things where students have seen the problem but not a thorough solution]
This puzzle can be solved using the pattern in binary numbers: http://www.cs4fn.org/binary/lock/
This site has more complex activities with binary numbers, including fractions, multiplication and division: http://courses.cs.vt.edu/~csonline/NumberSystems/Lessons/index.html