7. Data and Binary
We have already seen how numbers can be represented using the binary number system. What do we do about storing other types of information such as text, images or sound? One cool insight is that binary numbers can represent all such data.

7.1. Text via Binary Numbers
Imagine all the letters in the alphabet. We can consider assigning a number to each letter: A will be 1, B will be 2, and so on. Then we can present each word or paragraph as a series of numbers, and as we have seen, zeros and ones can store these numbers. Every word you see on the computer is represented by the help of such a system.

Using the coding above, we can encode the English word “DOG” by the binary sequence 001000111100111.


Most computers today use a fixed binary representation called ASCII (American Standard Code for Information Interchange), but some non-English speaking countries have to use longer codes. Note that different programs can choose to represent information in different way as well. For example, we can write a simple sentence and store as text file using Notepad or some other word processing software like Word. Notepad does not support all encodings that Word supports. In fact, if you try to open a Word file in Notepad you will see something similar to the image below.
This leads us to the idea of file types and file extensions. Even though two different files may store the same information, the programs used to create this information may choose a different encoding. Depending on the encoding used, we get a different file type. Usually, three characters after the filename identify the file type. These define the file extension. For example, a Word file has the extension
7.1.1 Sending Messages
Mehmood is trapped on the top floor of a department store. It is just before Eid and he wants to get home with his presents. What can he do? He does not have a cell phone. He has tried calling, even yelling, but there is no one around. Across the street he can see some computer person still working away late into the night. How could he attract her attention? Mehmood looks around to see what he could use.
Then he has a brilliant idea—he can use the lights to send her a message! He finds all the lights in the store and plugs them in so he can turn them on and off. He uses a simple binary code, which he knows the woman across the street is sure to understand. Can you work it out?

In order to help you get started, we have converted the first letter of the message below. Please finish decoding the entire message so help can come for Mehmood.
7.2. Images via Binary Numbers
How are images, video clips and all the graphics we see on the screen stored? All of these images are made up of tiny dots, called "pixels" (picture elements), and each pixel has its own color. A number in turn can represent each color. Considering that usually an image contains millions of pixels and a regular video shows 30 images per second, this is a huge amount of data.

As shown in the image above, every picture can be broken down into individual pixels. Three numbers between 0 and 255 give the color value for red, green and blue, which make up each pixel. Since 255 is the maximum value we can store in a byte, each RGB value takes up a total of three bytes.


In order to make things simpler, let us think of black and white pictures, where each pixel is either black or white.

As a result, when a computer needs to store a black and white picture, all that it needs to store is which dots are black and which are white. One obvious way to achieve this is to store one bit per pixel. Here, we show a more efficient way of storing this information.

The first line in the image above has one white pixel, followed by three black and then one white. So, the first line is represented as 1, 3, 1. It is important to note that in our scheme, the first number for each line always stores to the number of white pixels. If the first pixel is black, then the sequence of numbers will begin with a zero.
7.3. Sound via Binary Numbers
Let us briefly see how sound can also be represented by a series of numbers. Every sound is generally a series of movements in the air. These movements or "vibrations" can be represented graphically like an audio wave. A number can represent every point of this wave, and so any sound can be represented by a series of numbers. If we want better sound quality, we choose 32-bits to store our data rather than 8-bits. More bits mean a larger number range.


Instructions in Binary
The last missing piece of information that needs to be represented in binary are the programs or the set of instructions that we ask the computers to run and process all this information. In fact, if we recall that programming languages receive information using text, then we conclude that instructions also end up as a binary sequence. It is a story for another chapter that explains how we can make the computer understand our set of instructions.
The main outcome we take away for this is that all information from the real world can be encoded in binary and provided as input to the computer, which in turn can process based on our set of instructions, which are also in binary. That is cool!

7.4. Manual Fax
Shade in the following images using the encoding scheme discussed in class. The first picture is the easiest and the last one is the most complex. It is easy to make mistakes and so it is a good idea to use pencil to shade in the pixels and have an eraser handy!



7.5 Processing Activity
Type a letter to your friend in Word, in which you explain to him the encoding method we have discussed in class for black and white images. You should as part of the letter, draw the following table as an example for your friend and provide its encoding using numbers. Just like last time, aap agar Urdu mein letter likhna chahtay hain tu is tarhan letter likhain. The important thing is that your explanation is correct and you reproduce a table in Word, which shows the letter ‘b’.

You may want to play around with “Insert Table” Menu option in Word to build the table. After you have the right number of rows and columns, right click the table to figure out how to change the background color and other details. Remember to EXPERIMENT with different options!