What to expect
This chapter discusses binary, hexadecimal, character sets, images and sound. Some extracts are below.
Hand signals
We need to head over to France for an early binary code. Louis Braille injured an eye in his father’s leather workshop at the age of three, and the resulting infection caused him to go blind in both eyes by five. At age ten he obtained a scholarship to the Paris Institute for Blind Children, which at the time used a system of raised letters invented by Valentin Haüy. The letter shapes we know and love are not distinct enough to be easily discerned by touch, however, and Braille found Haüy’s system hard to learn.
While there, Braille was shown a system of raised dots used by the military to communicate at night. He took this system and improved upon it, using just six dots to represent all the letters of the alphabet plus numbers and some punctuation symbols. Each dot is raised or flat, and a blank space (effectively six flat dots) separates words and sentences. In this way, the grid of six dots could represent 2x2x2x2x2x2 = 26 or 64 different characters.
Magic Numbers
The importance of knowing the format of a file before processing it with application code is so important that there are two ways that a file identifies itself to the operating system. Windows uses file extensions such as .gif or .jpg and associates each extension with an application. It’s easy to accidentally change this extension, however, or even delete it. Meanwhile Unix-derived operating systems such as Linux and MacOS don’t use file associations anyway, so the metadata in the file header will also identify the content. For example, all JPEG files begin with the two bytes FFD8 in hex, GIFs begin with the ASCII string GIF89a, and PDFs begin %PDF. Because this trick originally used only numeric codes, this identifying string is still sometimes called the file’s “magic number”.
Misconception
The number of possible colours in a bitmap image is equal to the number of bits per pixel, so 4 bits gives 4 colours.
Reality
The number of possible colours is calculated as 2^bit depth, so 4 bits gives 2^4 = 16 colours, and 8 bits gives 2^8 = 256 colours. This misconception can be tackled by doing some student activities with low bit depths from 1 to 4, so they can see how the number of bit patterns, therefore the number of colours, doubles each time you add a bit.
TL;DR.
At the heart of this topic is the idea that as long as we can turn information into binary data, we can use a computer to process it. Digital computers process binary numbers because they use two-state electrical signals. The challenge is therefore to find a transformation from the real-world information to binary. This transformation is called encoding and it makes use of a code.
ASCII and Unicode are used to encode text, JPEG, GIF, PNG do the same for bitmap images, and WAV, MP3 and AAC encode digital sound. But it’s important to realise that there is a virtually limitless number of ways of encoding information, and these are just the techniques that are widely used due to effectiveness or official recognition, or both.
Analogue to digital conversion is the process of mapping the original data to the digital representation, and it’s vital to understand binary to really grasp the importance of bit depth and resolution and their effect on file size. Metadata is “data about data” and describes the contents of the file or something about the original information.
References
The PCK section in this chapter includes these references:
Use Python with an image library such as PIL, create and demonstrate some sample code, and then allow the students to edit it to make their own image filters. Some sample code is here, this program is easily edited to change the colour cast of a JPEG image. https://repl.it/@mraharrison/redfilter .
Martin O’ Hanlon has created a whole course on using Python with image filters here: https://www.futurelearn.com/info/courses/representing-data-with-images-and-sound/
Image filters (above) are a great means of linking programming to data representation. You could also link Programming with sound data, using a Python library such as wave https://docs.python.org/3/library/mm.html
Bitmap image creation is a great topic for unplugged activities. Give the learners a grid of empty pixels and a colour code and ask them to reveal the picture. They can then make their own picture, save it as numeric data and give the numbers to a partner who then reveals the image. Some sample activities of this nature are here:
- https://csunplugged.org/en/resources/pixel-painter/
- http://www.cs4fn.org/pixels/pixels.html
- https://projects.raspberrypi.org/en/projects/pixel-art-unplugged
The Micro:Bit™ has a built in 5 by 5 grid of LEDs which can be set easily with blocks or text coding, perfect for teaching 1-bit bitmaps. If you have a Raspberry Pi with the camera attachment, you can take pictures and process them with Python. You can use the Minecraft API to store these images in a “photobooth” within the Minecraft world with this tutorial here: https://projects.raspberrypi.org/en/projects/minecraft-photobooth
Using the open-source software Audacity, learners can get hands on with sound recordings, finding out how the sample rate and bit depth affects sound quality and file size. The NCCE resources include a great lesson on this here: ncce.io/rep2-5-p Add a microphone for even more hands-on fun.
More references here
[21] Ada Lovelace from https://findingada.com/shop/a-passion-for-science-stories-of-discovery-and-invention/ada-lovelace-victorian-computing-visionary/
[22] https://datagenetics.com/blog/march42012/results.html
[23] https://nyheritage.org/exhibits/making-sense-census/census-united-states-constitution
[25] https://en.wikipedia.org/wiki/Lace_card
[26] http://www.consortiuminfo.org/standardsblog/articles/unicode-80-song-praise-unsung-heroes
[27]https://faxauthority.com/biographies/alexander-bain/#alexander_bain_fascimile_machine
[28] https://en.wikipedia.org/wiki/Framebuffer
[29] https://w3techs.com/blog/entry/the_png_image_file_format_is_now_more_popular_than_gif
[31]https://repl.it/@mraharrison/redfilter
[32]https://www.futurelearn.com/info/courses/representing-data-with-images-and-sound/
[33] https://docs.python.org/3/library/mm.html .
[34] https://csunplugged.org/en/resources/pixel-painter/ , http://www.cs4fn.org/pixels/pixels.html, https://projects.raspberrypi.org/en/projects/pixel-art-unplugged
[35] https://projects.raspberrypi.org/en/projects/minecraft-photobooth
[36] ncce.io/rep2-5-p