Python is a programming language used to write programs or set of instructions for a computer. Before jumping directly into learning how to program a computer, it is useful to clarify what a computer is, how it works, and how we can instruct it to perform a specific task.

A good starting point about understanding computers is knowing that although computers process information differently from humans, we can draw parallels between the two processes. For instance, if the only language you understand is English, you will find it challenging to process the meaning of a text written in another language, say Swahili. For your brain to process the information, it must be provided in a representation that you can comprehend.

Visual actions are something people can understand even if they don't speak the same language. It's another representation that humans can understand apart from language. Similarly, computers can work with information when delivered in a representation that they can "understand".

However, saying computers understand information seems a bit odd. Do you think computers really understand the information they are provided?

Saying that computers understand the information is a bit like saying light switches understand that they are switching off or switching on the lights. But for the sake of convenience, we will continue using the term. When we say computers understand information, you can think of it as the computer knows what's to do with the information.


Which form of representation do you think, computers can understand?

The representation that a computer understands is usually in the form of ones and zeroes. Everything on a computer that you see is first expressed in the form of ones and zeroes for the computer to process it. And then the computer represents it back to a representation that you can understand. That's how computing works, in a nutshell.

Can you name a couple of things that you see on a computer?

You can see a bunch of text and images on a browser. You can watch cat videos and listen to your favorite music on the computer. All of these are represented in ones and zeroes for the computer to work with them.

To understand how computers work, we first need to understand how we can represent texts, images, and sounds in the form of zeroes and ones. However, even before that, we need to start with numbers and understand how computers process numbers. Let's take a look.

Representation of numbers

Why do you think humans invented numbers?

Numbers are universal to all human beings. Every human, irrespective of what language they speak, counts things using numbers. Researchers may have different opinions about when humans invented the numbers. However, they generally tend to agree on the earliest utility of numbers: Counting. Let's take a look at how the current method of counting numbers came into existence.

Early Number Systems

The early humans needed a tool to count their possessions, animals in a flock, or members in a tribe, and thus the numbers came into being. To communicate the amount of the object, they could draw the same object that many times. These drawings are called pictographs,  a pictorial symbol for a word or phrase.

For instance, figure 1 represents a pictograph of 5 hens.

Five Hens
Figure 1: Pictograph of Hens

Eventually, drawing multiple instances of the same object became cumbersome. They switched over to drawing one instance of the object while representing its quantity by lines. These were tally marks.

Figure 2: Tally marks representing five hens
Figure 2: Tally marks representing five hens

Figure 2 represents five hens using tally marks using a single pictograph of a hen. The number of lines represents the amount of the object. This system was useful for keeping small quantities but for larger quantities proved to be cumbersome.

As early civilizations developed, they came up with different ways of writing down numbers. Many of these systems, including Greek, Egyptian, and Hebrew numerals, were essentially extensions of tally marks. These systems denoted new symbols to represent a higher magnitude of value.

In Egypt, for instance, a knot on the rope or coiled rope represented 100, while two knots represented 500. These pictorial symbols are referred to as hieroglyphs. Figure 3 shows some of the hieroglyphs and their meaning and the value of the number they represented in the Egyptian Numbering system.

Figure 3: Egyptian Numbering System

In the Egyptian numbering system, each symbol was repeated as many times necessary. Then all were added to get the number. This type of number system is called an additive system.

An additive system is one in which the number represented by a particular set of numerals is simply the sum of the numerals' values. The Egyptian System is considered the first additive system. The order is irrelevant for the numerals.

In figure 4, we represent the number 3212 using the Egyptian numbering system.

Figure 4: The number 3212 in the Egyptian numbering system

What number does the hieroglyph in below figure represent? Figure 4a: Three sticks, two heel bones, three coiled ropes and 5 lotus flowers

  1. 5323
  2. 7523
  3. 6743
  4. 5843

The representation of numbers in the additive system, too, was cumbersome for many numbers. Therefore, the Romans improved the overall system by adding another rule.

If the symbol appearing is smaller than the previous, it should be subtracted rather than added.

Let's look at the Roman numeral system.

Roman Numeral System

To understand the Roman Numerals, let's get familiar with some of its numerals. Table 1 shows some of the symbols from the Roman Numerals Systems.

Table 1: Roman Numerals
Number Roman
1 I
2 II
4 IV
5 V
9 IX
10 X
12 XII
50 L
100 C
500 D

Roman numerals are not a purely additive number system. Roman numerals are usually written in order, from largest to smallest and from left to right. More than three identical symbols never appear in a row. Instead, a system to substraction is used.

For instance,
Three = I + I + I = III \\
Four = V - I = IV \\
Eight = V + I + I + I = VIII \\
Nine = X - I = IX

We can write larger numbers using the Roman System while keeping two rules in mind:

When a symbol appears after a larger (or equal) symbol, it is added
VI = V + I = 5 + 1 = 6

CXX = C + X + X = 100 + 10 + 10 = 120

If the symbol appears before a larger symbol, it is subtracted

IV = V − I = 5 − 1 = 4

IX = X − I = 10 − 1 = 9

Let' take the $DXLVII$ as an example.

  • $D$ is larger than $X$, therefore add 500

D = 500

  • The next numeral, $X$, is smaller than $L$. Therefore we will take both of them together and subtract $X$ from $L$:

L - X = 40

  • The next numeral is $V$. Since $I$ is smaller than $V$, we will add the remaining digits to get the value.

VII = 7

Adding all up, we get 547.

What is the value of the following Roman numeral?$$CCCLXVII$$

  1. 547
  2. 367
  3. 333
  4. 387

In contrast to the numbering system, language became sophisticated sooner. Humans could reference objects using a group of symbols or vocalizing rather than drawing objects. There were only a finite number of objects and actions that needed to be communicated in day to day life. However, there was still the problem of numbers. Numbers are infinite.

We cannot assign each number a unique symbol as we will run out of symbols, but the numbers wouldn't end. The additive systems were cumbersome to represent higher numbers.

What do you think humans did to overcome that?

The humans figured out how to use finite symbols to represent all possible numbers in a compact notation.

The humans developed a positional system for numbers. Let's take a look.

Positional Numbering System

The positional system allowed humans to define some unique symbols for numbers and then reuse them by assigning them different values based on their position in the sequence.

In a positional numeral system, we can represent numbers using an ordered set of numerals symbols (called digits). The value of a numeral symbol depends on its position.

Several civilizations developed positional notation independently, including the Babylonians, the Chinese, and the Aztecs.

Around the 7th century, Indian mathematicians perfected the positional number system by introducing $0$ (zero). The positional numeral system, pretty the same as the one which we use today, used only ten unique symbols and could represent any possible number.

The Italian mathematician Leonardo Bonacci, most popularly known as Leonardo of Pisa or Fibonacci, is considered responsible for spreading the use of Indian Numerals throughout Europe after the publication of his book, Liber Abaci in the year 1202. In the book, he notes,

The method of the Indians (Latin Modus Indoram) surpasses any known method to compute. It's a marvelous method. They do their computations using nine figures and the symbol zero.

The symbol 0 could act as a placeholder for the value that represents nothing. The symbol 0 was the missing ingredient which the earlier number system lacked. To understand, let's look at the first ten whole numbers we use today.
\text{First ten whole numbers : }  0, 1, 2, 3, 4, 5, 6,7, 8, 9 ...
Each number is represented by a unique symbol or digit for the first ten whole numbers. After the first ten whole numbers, the number is ten(10) represented by 1 followed by  0.

The digits 1 and 0 representing 10 are not unique symbols anymore. They have already been used to represent a quantity in the first ten whole numbers.  However, when the digit occupies a different position, it represents a unique value. The numbers that follow the first ten digits reuse the unique symbols to represent a different number.
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ...
Therefore, we can represent any number in this form by reusing only ten unique digits or symbols.

Why do you think there are only ten unique symbols in the number system?

It is very probable that there are only ten unique symbols because humans have ten fingers, which were used for (finger) counting earlier. Because we are using only ten unique symbols, this system is called decimal numeral system.

The decimal numeral system is also called positional notation system with base ten, where base (also called radix) means the number of unique symbols.

You can create different systems by taking different unique symbols or base.

The Babylonians developed a numbering system of base 60 or Sexagesimal numbering system.

Guess where the Babylonian's numbering system is used.

The base 60 is still used, although in a modified form - for measuring time, angles, and geographic coordinates. For instance, each day is made up of 60 minute hours and 60 second minutes.

In computing, we use only a number two digits — 0 and 1. What is the base of such a numbering system?

Since there are only two numerals (0 and 1) to represent every possible number, the base is 2. The base two numbering system is called binary numbering system.

Binary Numbering System

The first binary number is 0, and the next is  1. The decimal number 2 is  10 in binary. Because we have exhausted the number of unique symbols, we will increase the places. Therefore, in binary the next number three is $11$, four is $100$ and five is $101$. The trick is cycling from 0 to 1 and increasing the number of digits on the left-hand side.

Binary numbers are written in the group of four with $0$ padding the leading numbers. For instance, we can write five as $0101$.

Here are numbers 3 - 8 in binary jumbled. Why don't you try to rearrange them in ascending order?

  1. 1000
  2. 0100
  3. 0110
  4. 0101
  5. 0011
  6. 0111

Hexadecimal Numbering System

Another number system often used in computing is the hexadecimal numbering system or base-16 system. The 16 unique numerals, in this case, ranges from 0-9 and A-F.

It might seem a bit confusing to understand how symbols A-F are used in the numbering system.  Table 2  shows the first couple of numbers in the hexadecimal numbering system.

Table 2: First 18 hexadecimal numbers
Decimal Number Hexadecimal Number Decimal Number Hexadecimal Number
0 016 9 916
1 116 10 A16
2 216 11 B16
3 316 12 C16
4 416 13 D16
5 516 14 E16
6 616 15 F16
7 716 16 1016
8 816 17 1116

To differentiate between numbers on different bases, we write in one of the following ways:

  1. add a subscript indicating the base to the end of the number. For example, 716
  2. add prefix indicating the base.  Binary numbers have the prefix 0b while hexadecimal numbers have the prefix 0x.  For instance, 0x7.

As we use the decimal system of numbers in our day-to-day life, we usually skip writing the decimal base. If you see a number without its base specified, you can assume it's in the decimal system.

Table 3: Representation of numbers in different numbering system
Decimal - Base 10 Binary - Base 2 Hexadecimal - Base 16
8 0b1000 0x8
14 0b1110 0xE
103 0b1100111 0x67
143 0b10001111 0x8F
511 0b111111111 0x1FF

Table 3 shows numbers on all three bases. Each of the numbers in a row is the same number represented with a different base. As you can notice, we can represent a number in various base.

What is the value of the number 0x68 in decimal?

  1. 104
  2. 105
  3. 106
  4. 102

In previous quiz, you can easily figure out the value of 0x68 by checking table 3, where the value of 0x67 is shown. However, it's not convenient to refer to some table to figure out the decimal representation.

It makes sense to learn a simple method to convert numbers from different bases into a decimal so that you can understand. Let's understand the positional notation system to understand how to convert numbers from different bases to their decimal representation.

Positional Notation System

In a positional notation system,

  • the place value of each digit position is the value of its digit, multiplied by a power of the base.
  • The power of the base is determined by the digit's position index.

Depending on what position index they occupy, the digit's place value can be determined using the following formulae.
\text{Place value of a digit } = \text{Value of the digit } \times (base)^{index} \tag{1}
The position index starts from 0 for the rightmost digit and increases by one as it moves towards the left. If we add all the place values, we will get the number in the decimal system.

For example, in decimal system, the number 456 can be read as Four hundred and fifty six. We can represent the number 456 in the expanded form as follows:
456 &= 4\times10^2 + 5\times10^1 + 6\times10^0 \\
&= 400 + 50 + 6 \\

  • base of the number is 10
  • 4 occupies the 2nd index therefore it is read as 400
  • 5 in it's 1st index is read as 50
  • 6 in its 0th index is read simply 6.

We can obtain the number represented in the decimal system by adding all its digit's place value.

$$ (a_n...a_0)_b =\sum_{i=0}^{n}{\text{Place Value of } a_i } = \sum_{i=0}^{n}{a \times b^{i}} \tag{2}$$

\text{where a is the place value of the digit, } \text{b is the base &} \text{ i is the position index}

Equation 2 shows the formula to get the expanded decimal system representation of a number. We can represent any number in the expanded form using equation 2.  Here are a couple of numbers in the decimal system and their expanded form.
5_{10}  = 5\times10^0 \\
78_{10} = 7\times10^1 + 8\times10^0 \\
512_{10} = 5 \times 10^2 + 10 \times 10^1 + \times 10^0 \\

What is the place value of 5 in 5123?

  1. 5000
  2. 500
  3. 1000
  4. 100

We can convert a number in a different base to the decimal system by adding the place value of each digit. Let's start with converting binary numbers into decimals.

Here are some numbers in binary and their corresponding representation in decimal.
1000_2 = 1 \times 2^3 + 0 \times 2^2 + 0 \times 2^1 + 0 \times 2^0 = 8_{10}   \\
1110_2 = 1 \times 2^3 + 1 \times 2^2 + 1 \times 2^1 + 0 \times 2^0  = 14_{10} \\
Similarly, we can convert the hexadecimal numbers into the decimal system. The following shows the conversion of some hexadecimal numbers into decimals.
67_{16} =  6 \times 16^1 + 7 \times 16^0 = 103_{10} \\
8F_{16} =  8 \times 16^1 + 15 \times 16^0 = 143_{10}

What is the place value F in 0xF5?

  1. 245
  2. 246
  3. 240
  4. 247

In this section, we saw that every number could have various representations. We can also represent other forms of information such as text, image, and sound into a binary representation. In the next section, we will look into how to do that.

Text, Image & Sound Representation in Binary

Consider the following scenario.

You went out on a solo adventure on a sailboat into the ocean. You have a wind-powered boat without an engine. At some point during your voyage, you enter into a windless patch of water, and the boat gets stuck. You get stuck for weeks, with nothing in view but water. At the same time, your navigation and communication devices run out of power. The only working equipment you have left is a signal lamp.
One day, you see a group of ships passing at some distance from your boat during the night. The question is, how do you ask for help?
How do you ask for help to the ships?

The clue of the signal lamp reveals out that it needs to be used to ask for help. You can use the signal lamp to ask for help. However, you can not simply randomly flash signals hoping that the ship will come to rescue you. Then how exactly to use a signal lamp to do that? The way you can ask for help is by signaling S.O.S. using your signal lamp.

S.O.S. is an internationally accepted distress signal used during emergencies.

Contrary to popular belief, S.O.S. doesn't stand for anything.  The phrases "Save our Souls" and "Save Our Ships " are, in fact, backronym rather than an acronym. When you flash distress signals, other boats will understand that you require help and will come to your aid, given that they can see it.

At this point, two questions might be unclear.

How can flashing a signal lamp in a fixed pattern mean S.O.S.?

How to flash a signal lamp so that it means S.O.S.?

Before we answer these two questions that let's take another scenario.

Suppose there is a multiple-choice based test. Each question has four options, from which the only one is correct. You and your friend decided to develop a communication strategy to cheat during the test.
Keeping in mind that I am in no way encouraging cheating off tests, how will you and your friend manage to exchange answers?

The obvious way is to use distinct gestures to symbolize different options. An example would be scratching your hair to represent option A or rubbing your eyes for option B, and so on. This method should help you communicate effectively without raising suspicions.

Let's take a moment to reflect. We just created something interesting here. What do you think we created when we used gestures to symbolize an answer?

We created a code that could only be understood between you and your friend. It is a secret language that you can speak with those who understand its meaning.

We can formally define code as a system of words, letters, signals, or symbols to transmit a message in secret form or a more convenient form.

The code you developed to exchange your friend's answers was to transmit a message in a secret form. One reason for coding is to enable communication in places where ordinary plain language, spoken or written, is difficult or impossible. Such as being stuck in a sailboat in the middle of a windless ocean. Flashing S.O.S. using a signal lamp, in the absence of other communication devices, is a convenient way to transmit requests for help.

When you convert information into symbols, the process is called encoding.

To encode a message, you must first define or use an existing standardized coding system.

While the reverse process of encoding is decoding.

What do you think is decoding?
Decoding is the process when you convert back the encoded symbols to retrieve the original message.

When your friend scratches his head, you can understand that he means the option A referring to your previously agreed code system.  There is no standardized system of cheating off in tests. Therefore, we usually create our system and assign them value.

We will use a widely used coding system called Morse code to communicate in the middle of the sea.

Morse Code

Morse code is a method used to encode characters as standardized sequences of two different signal duration.

These two signals are represented by dots (.) and dashes (_). The International Morse Code encodes the 26 English letters A-Z, some non-English letters, the Hindu-Arabic numerals, and a small punctuation set. There is no distinction between upper and lower case letters. We can take a look at the International Morse Code for 26 alphabets in table 4.

Table 4: International Morse Code
Alphabet Morse Code Alphabet Morse Code
A . _ N _ .
B _ . . . O _ _ _
C _ . _ . P . _ _ .
D _ . Q _ _ . _
E . R . _ .
F . . _ . S . . .
G _ _ . T _
H . . . . U . . _
I . . V . . . _
J . _ _ _ W . _ _
K _ . _ X _ . . _
L . _ . . Y _ . _ _
M _ _ Z _ _ . .

When you wish to send some messages using Morse Code, you will first have to convert your message in the Morse Code using the International Morse Code. Then you can send it through a communication channel or store it in a storage medium.

The receiver can decipher or decode the information contained by looking into the International Morse Code upon receiving the message.

What is the value of the following code written in morse code?$$\text{_ _ _ _ . _}$$

  1. O.K.
  2. C.Q.
  3. F.W.
  4. O.I.

Using the Morse code shown in table 4, we can encode alphabets in dots and dashes and send signals. We will use the signal lamp as a communication channel to transmit signals in our earlier case. Let's figure out how to use the signal lamp for communicating S.O.S.

In the International Morse Code, a dot is a single unit duration while a dash is three units duration. For using the signal lamp for communicating, we can assign the following:
\text{Flashing for a single second } = dot  \\ \text{Flashing for three seconds } = dash \tag{3}
Now we are ready to send a message across for help. In the International Morse Code shown in table 4, we can see that code for S is ... while for O is _ _ _. So, we can encode our message of S.O.S. in the following form.
\text{SOS  } =\text{  . . .    _ _ _    . . .} \tag{4}
Using our method of using the signal lamp as a communication channel, we can do the following:

  1. Flash for a second three times consecutively
  2. Flash for three seconds three times consecutively
  3. Flash for a second three times consecutively
  4. Repeat

If other ships receive your message, they will decode or interpret your message and come for help. You might notice that it takes around 15-20 seconds for someone to understand your message. You can make the process faster by proportionately reducing the signal lamp flashing duration.

Hopefully, now you have a little bit of an idea about code textual information in other representations such as gestures, signals, or even flashing.

Earlier, we primarily used Morse code in the telegraph. It's not used in computing anymore. However, you can say that Morse Code was an inspiration for text encoding in modern computing.

What does the Morse code using dots and dashes reminds you of with relation to the number system?

Representing text in Morse code using dots and dashes is similar to representing any number using only two numerals, i.e., $0$s and $1$s. Earlier, we saw that we could represent every number into binary representation while using only two numerals ($0$ and $1$).

Now that we understand how to code text in other representations, let's look into how we can encode text in a binary system for efficient communication.

Binary Representation of Text

To convert text into binary, we first require defining a mapping of the basic alphabets and characters. One of the examples of such mapping is the International Morse Code.

There are only two values a signal can take, dot and dash in a basic variation of Morse code. Therefore we can presume it to be similar to the binary number system.

The International Morse allows various combinations of dots and dashes to represent the alphabet of the English Language. Although the Morse Code is not binary in the strictest terms.

Can you guess as to what the word binary means?

The word binary means having two possible states like the binary numeral system. Each digit can be either 1 or 0. The states can also be defined as on & off or true & false.

A device that can be on the two possible states is called a single binary or two-state device.
Can you think of an example of a binary device?

An example of a binary device is an electronic switch that can either be on or off. Another example would be a light bulb, which can be turned on or off can act as a binary device. Earlier, we used a signal lamp to act as a binary device by assigning the two states.

A single binary digit or single on/off value is called a bit (Binary digit). A bit is also the basic unit of information or data.  Therefore, a single binary device is said to hold one bit of information.

Since a single bit can hold very little information, we often line many bits to store information. For convenience, a group of eight bits is called a byte. Each of these combinations can be assigned a symbol or information, just like the Morse Code.

If we take the value of light switch being on as $1$ and being off as $0$, the possible combinations or bit pattern of three switches is shown in table 5. We can store the symbols A-G using combinations of three light switches.

Table 5: Bit Patterns using three binary devices
Bit Pattern Decimal Number Assigned Meaning
0b000 0 Space
0b001 1 A
0b010 2 B
0b011 3 C
0b100 4 D
0b101 5 E
0b110 6 F
0b111 7 G

If you need to store all the alphabets in the English language and punctuation marks, we will require more bits. Being a binary number, they can also be represented in the form of their decimal counterpart.

Using table 5, let's implement a bit pattern that encodes a word.

Binary numbers are usually grouped into a set of four, separated by space. We can write the word BAD as 0b 0010 0001 0100.

Let's implement a binary code using a bunch of binary devices.

Figure 5: Representing BAD GABE using light switches

Figure 5 shows how the message BAD GABE can be represented using light switches. Anyone who has access to the character encoding shown in the the table above 5, will successfully decode the message. To include the space character in BAD GABE, we can include 0b0000 into the pattern. 0b000 means three switched off bulbs.

What text does the bit pattern 0b 0110 0100 1100 1010 represent according to table 5?

  1. $CAFE$
  2. $ACE$
  3. $GAFE$
  4. $FEDA$

Text Representation in Computers

Let's take a look at how text is represented in computers. When any key on a keyboard is pressed, a signal encoding a binary number is generated. According to a standardized character encoding, this signal is processed by the computer. It results in the typed character to appear on the screen.

Their several standardized character encoding, which encodes various characters or symbols to a binary number. Let's look at one called ASCII.

ASCII is a standardized code abbreviated from American Standard Code for Information Interchange. Before computers, telegraphs were mainly used for long-distance communication. Telegraphs used ASCII to encode information to send it over the wire.

The ASCII code takes each character on the keyboard and assigns it to a number. For instance, character A is assigned the number 65 or the binary number 0b 0100 0001. Table 6 shows the association of the symbols with numbers in ASCII.

Table 6: ASCII Symbols
Range of Numbers Assigned Symbols
33 - 47 Special Characters ( ! / + ...)
48 - 57 Numbers ( 0 - 9)
65 - 90 Uppercase Alphabets ( A - Z)
97 - 122 Lowercase Alphabets ( a - z)

ASCII code is a 7-bit character set. The highest binary number you can assign in ASCII is 0b 111 1111.

How many characters can be assigned to numbers using 7-bits?

You can only encode 27 or 128 unique symbols or characters using 7-bits. 128 symbols are quite less in comparison to our real-world needs.

If you wish to use the accents found in many European languages or a larger set of alphabets such as Cyrillic, Devanagari Script, or Mandarin, more bits are needed. A new set of standardized character encoding called Unicode was created to overcome ASCII's limitation. There are several sets of encoding available under Unicode. One of the popular Unicode character encodings is the UTF-8.

Unlike ASCII, UTF-8 uses several bytes. It can encode more than a million symbols, which is quite enough for all Earth's languages. Apart from text and characters from different languages, the UTF-8 also encodes emojis.

I hope you understood how the text elements are stored in the form of binary. Would you like to guess as to how images are stored in the form of binary? How do you think the computer stores images in binary and displays them onto the screen?

To understand how images are stored in binary, we need to look at what a digital image is. In the next section, we will see how computers display images.

Binary Representation of Images

A computer breaks an image into tiny elements called pixels to display it on a computer. A pixel (short for picture element) is a small square representing only one color. Lots of these pixels together can form a digital image.

Figure 6: Binary Image

The computer represents each pixel with a binary value to store an image. Depending on the number of bits in the binary value, we can choose to represent a different number of colors. For instance, figure 6 shows an image with two colors: black and white and uses a single bit to represent each pixel.

Therefore, every pixel in figure 6 is either 1 or 0.  Depending on whether the pixel has the value 1 or 0, it displayed as black or white, respectively.

When we represent an image using only two colors, it is called a binary image. Figure 6 shows that we can represent an image of F using pixels, which take only 1 bit and can either be black (1) or white (0).

Computer stores an image in the form of binary values spanning several lines. Each line is encoded from left to right and top to bottom. The image in figure 6 can be stored using the following binary values shown in figure 7.

Figure 7: Binary Values corresponding to rows of image pixels

For a computer to draw or interpret the image from the binary values, it needs more information other than the binary values. It requires numbers of pixels present in a row or width of the image and the number of columns or the height of the image. It also requires the number of bits used to represent each pixel. The number of bits used to represent each pixel is called color depth. The resolution of an image is a way of describing how tightly packed the pixels are.

The extra pieces of information such as color depth required for the computer to correctly display the image from binary numbers are called image metadata.

What do you think is the color depth, height, and width of the image in figure 7?

  1. 1-bit, 8 pixels height, 8 pixels width
  2. 2-bit, 16 pixels height, 16 pixels width
  3. 1-bit, 9 pixels height, 10 pixels width
  4. 2-bit, 9 pixels height, 10 pixels width

In the previous quiz, the color depth is 1-bit, as only 1-bit is used to represent each pixel while the image is 8 pixels high and 8 pixels wide.

An image that uses 4 colours requires at least 2-bits ( $2^2 = 4$ ) to represent each pixel.

2-bit Image
Figure 8: 2-bit image

Figure 8 shows a 2-bit image along with its binary values of image rows. In figure 8, the mapping of the colors for the corresponding bits is shown in table 7.

Table 7: 2-bit color map
Bit Pattern Color
00 White
01 Orange
10 Blue
11 Green

The mapping of bits to colours is called colour bitmap. The metadata for the above image in the figure 8 is as follows:

  • colour depth: 2-bit is used to represent each pixel
  • resolution: 6 pixels ( width ) x 7 pixels ( height ) = 42 pixels image resolution

On providing the binary values and the metadata, a computer will interpret the image and correctly render it.

A 2-bit color depth image can use only four colors. To represent images accurately, we require a higher color-depth.

If we use 16-bits to represent a single pixel, it can represent $2^{16}$ or 65,536. If we use 24-bits to represent a single pixel, it can represent $2^{24}$or 16,777,216 colors.

Can you guess the number of colors the average human eye can discern?

The average human eye can usually discern up to 10 million colors. Therefore, using 24-bit color depth is usually sufficient for most practical purposes.

Colour depth comparison
Figure 9: An image in different color depths

In figure 9, we can see the same image in various color-depths. Because pixels are very tiny in size, even with 1-bit color depth, the image detail is quite clear.

In this section, we briefly covered how computers convert images into binary. In the next section, we will look into how computers convert sounds into binary.

Binary Representation of Sound

To convert sound into binary, we must first capture it.

Which device do you think is used for capturing sound?

Capturing of sound is done using a microphone. A microphone is a type of transducer that converts the sound wave into an electrical signal. A transducer is a device that converts one form of energy to another.

Can you think of a device that converts electrical signals into sound?

A loud speaker is a transducer that converts an electrical signal into sound. Let's look into how a microphone converts sound into electrical signals.

A sound wave causes rapid air pressure variations, and a microphone is sensitive to these minor fluctuations in air pressure. A sensor is attached to the microphone whose electrical conductivity depends on the air pressure. When current passes through the sensor, the flow of electricity varies according to the air pressure variations. A device measures the fluctuating level of current called an Analog-to-digital converter (A.D.C.).

As sound waves are continuous, the A.D.C. takes precise measurements at a large number of times per second ( for instance, 44,000 times a second ) and creates a number representing the air-pressure at that time. The number of measurements or time samples per second is called the sampling rate. We measure the sampling-rate in kilo-Hertz ( kHz ). 1 Hz is one sample per second. Most CD-quality audio is sampled at 48 kHz or 48,000 samples per second.

We can then convert the collected samples into binary. They are recorded to the nearest whole number. If we plot the time samples, we will see that the sound wave now looks different because sampling does not consider what the sound wave is doing between each time sample. The sound loses quality as we are losing data between the time samples.

Figure 10 shows a graph of sample pressure variations and the corresponding sampling to digitally reconstruct the wave:

Sampling of Audio Signal
Figure 10: Sampling Audio Signals
How can we increase the quality of the reconstructred or stored sound?

In figure 10, we can see that based on how often the audio signal's measurement, the better is the reconstructed signal.

The higher the sampling rate, the more accurate its reconstructed wave is.

We can collect more detail about the sound this way. It does not lose as much quality when it’s converted to digital and back to analog again.

This is a brief overview of how sound is converted to binary. Do you want to guess as to how the binary values are played back?

The reverse process of recording sound is used to read the binary values and play the stored sound file.The stored binary values are read and transmitted to a something called Digital-to-Analog converter (D.A.C.).

First, a device reads stored binary values. A Digital-to-Analog converter generates a strong or weak current on a wire, depending on the number. A speaker can reconstruct the sound vibrations from the electrical audio signals. It is close to the original air vibrations during recording.

We can see the entire process of recording and playing the sound waves in figure 11.

Figure 11: Process of recording and playing sound

A point to note is that, when we measure the sound wave 48000 times a second, the storage space required quickly becomes huge. There are many compression techniques available that can shrink the size of the data without loss of information. These are called data compression techniques. This is a brief overview of how sound is stored in binary and played back on the computer. Let's do a short exercise.

Can you re-arrange the order of how sound is recorded and played back?

  1. Sound wave causes rapid air pressure variations
  2. Current passes through a microphone fluctuate according to the fluctuating air pressure
  3. A.D.C. takes precise samples of the fluctuating at a large number of times per second.
  4. The collected samples are stored in binary to the nearest whole number
  5. The stored binary values are read and passed to the D.A.C.
  6. The D.A.C. generates current on a wire depending on the number from the stored binary values.
  7. A speaker can generate sound from the fluctuating current.

So far, we have covered how sound, images, texts, and numbers can be converted into binary. At this point, you might be interested to know why binary or base-2 is used. Why not ternary (base-3) or decimal?

Guess of one good reason why we use binary instead of other bases?

Why binary is used in Computers

There are several advantages of using binary in computers. Here are four of the important reasons for using binary:

  1. Versatile Representation
  2. Binary devices are simple to build
  3. Signals in the form of binary are unambiguous
  4. We can create flawless copies of binary data.

Let's look into each of these reasons in a bit more detail.

Versatile Representation

The first advantage of using binary is we can use it to encode various types of information.

We have already seen earlier that numbers and text, image, and sound store in binary form. We can use patterns of bits to represent almost anything that follows some sort of pattern.

Binary representation is versatile enough to accommodate different types of data.

A more complex example would be videos in which images, along with the sound, can be stored in binary form. This ability to be able to represent almost anything is a major advantage of using binary.

Before moving on to the next advantage, let me ask you a question. A light switch is a device that has only two states on and off. A light dimmer is a device with multiple states and is used to control the brightness of the light. Which one do you think is easier to build - A light dimmer or a light switch?

Binary Devices

A light dimmer must gradually and smoothly change the current that reaches the light. It has more components than a light switch and must be carefully assembled. A light switch with two possibles states on and off is quite simple and easy to build compared to a light dimmer. The second advantage of using binary is - binary devices are easier to build.

This is also true for the tiny binary devices inside a silicon chip or magnetic storage, which powers modern computing. Switches with only two states are relatively easy to fabricate or produce. These binary devices are cheap, small, and reliable, and often billions of them can fit into a small area.

There are several ways to implement a bit pattern. Here are some ways we can implement bit patterns:

  • An electrical switch
  • Voltage on a wire.
  • A transistor
  • A small part of the light-reflecting surface, for example, C.D.s.
  • Part of a radio signal.
  • Part of an audio signal.

Earlier, we stored the message BAD GABE using twenty-four light-bulbs. Twenty-four light-bulbs can hold only 24 bits of information. A group of eight bits is called a byte.

Using light-bulbs to store information becomes expensive to keep a larger amount of information as they occupy a larger size. The hard-drives on a computer usually use which magnetic storage can hold more than 512 Gigabytes of data or 512 000 000 000 bytes or 512 billion bytes of information. That's a lot of storage.

Unambiguous Signals

There are three things you can do with information. You can store information, transmit information or process/transform information. The third advantage of using binary relates to information or signal transmission.

Before we move onto the advantage, what do you think does the word unambiguous mean?

The word unambiguous  essentially means not open to more than one interpretation.

The third advantage of using binary data is: Binary signal transmission is unambiguous and is immune to noise.

Let's take an example to understand this more.

Earlier, we suggested a hypothetical scenario where you and your friend decided to create a code to exchange answers during a multiple-choice questions based test. Suppose your friend suggested an unconventional method of transmitting code signals corresponding to the answer, shown in table 8.

Table 8: Unconventional Code Signals
Code Signals Answer
Motioning A using finger A
Motioning B using finger B
Motioning C using finger C
Motioning D using finger D

First of all, cheating off tests is not the right thing to do. Second, if you must cheat, then the above method is a recipe for disaster. It's unclear, it is prone to confusion, and most importantly, it's stupid.

Can you figure out what's exactly wrong with this method of communication?

When your friend is motioning, let's say the letter A, to get the full signal, you must observe the motion for the full duration. If you miss out on the part of the signal, you will most probably miss out on the entire information transmitted by the signal.

A better way is defining four different states corresponding to each answer, which are unambiguous and don't cause any confusion. For example,

Table 9: Conventional Code Signals
Code Signals Answer
Scratching hair A
Touching the forehead with the tip of a pen B
Touching nose with the tip of a pen C
Touching chin using the tip of a pen D

The signals mentioned in table 9 are a much effective way to communicate without any confusion. When your friend signals the answer A by scratching his hair, you can understand it even if you miss out on some portion of the movement.

Signals that continuously change values and can be anything in a range are called analog signals.

The sound waves we saw in the figure 10 are continuous signals. While signals that have a finite number of states are discrete signals. Discrete signals change only at discrete instants of time. Such signals are called discrete signals because they have a fixed number of definite states.

Binary signals are discrete signals.

The above two types of code signals differentiate between two types of signal - discrete and analog signals. Analog signals continuously vary with time. Their exact value at any particular instant is important for the receiver. This is similar to the code signal mentioned in table 8. Whereas in discrete signals, the receiver is interested in discrete states. As you might notice in the able two examples, discrete signals are unambiguous.

We can understand the noise immunity aspect of discrete signals using another example.

Noise Immunity
Earlier, I mentioned that the voltage on a wire could transmit a signal. Can guess how to use the voltage on a wire to transmit signals?

We can use the voltage on a wire to pass information in coded form. If you wish to send information to someone using a wire, you can encode a message into a fluctuating voltage. The receiver can record the voltage over some time and decode our message.

However, when you transmit the analog signals over a communication channel, it is most susceptible to external noises, which might cause a loss of information. The transmitted analog signal and the received signal often turn out to be quite different, as shown in figure 12.

Analog Signal
Figure 12: Analog Signal Transmission

Analog signals continuously change their value, and the information they carry is the exact value at any instant. The exact value of an analog signal at any time is essential. Therefore, analog signals are significantly affected during imperfect transmission.

To convert the analog signal into discrete binary signals, we need to ensure that at any instant of time, a signal represents one of two values. How do you think we can do that?

Using a threshold value, we can convert an analog signal into binary or digital signal. In such cases, a signal represents only one of the two discrete states at a discrete-time interval. Once we convert the analog signal into a digital signal, we can send information through it.

For instance, if the signal is above the threshold value, say 0.5, it can be considered 1 and if below, then 0. The essential advantage of using digital signals is that we longer need to worry about the signal's exact value. In figure 13, we can see this in action.

Digital Signal
Figure 13: Digital Signal Transmission

In figure 13, you can see that even though there is noise in the received signal, the reconstructed digital signal doesn't incur any information loss. The reconstructed digital signal is the same as the sent digital signal. This is why digital signals are said to possess considerable noise immunity.

Perfect Copies

The fourth advantage of using binary is a continuation of digital signal advantage.

Lets say you downloaded a file from the internet using a good internet connection. Do you think there is a loss of information when a file is downloaded from the internet to your computer?

There is no or minimal information loss when a file is downloaded from the internet. You might be so used to the fact that you take this for granted. The files you download from the internet are perfect replicas of the original files.

The fourth advantage of using binary is - we can make perfect copies using binary.

When we use binary signals for transmission, the receiver is only interested in the binary values. All it does is check if the signal is above or below the threshold. The receiver can do this quite perfectly unless the noise is not too great. For example, in figure 13, the original binary signal and the reconstructed binary signal are identical even though there is noise in the received signal. The original signal is recovered perfectly.

This process of recovering the original signal in digital signal transmission can be repeated as many times as needed with a flawless perfect copy made each time.

Bit patterns are often copied back and forth between processor & memory more than millions of times per second in computers. The copies of stored information need to be perfect each time. In this particular case, binary signals are highly useful for creating perfect copies.

Information stored in binary form does not change when we copy it from one medium to another. We can create an unlimited number of such copies. The ability to make perfect copies without loss in information is a compelling combination. The chances are that you are already accustomed to this that it may not seem significant. When you try to download a video or music file from the internet, the data has already been copied (downloaded) many dozens of times, using various transmission and storage methods. Yet, it doesn't affect your download, and you get a perfect replica of the data.

Video Streaming
Figure 14: Streaming video through various communication channels

Figure 14 shows a sample demonstration of how a simple download of the video passes through various storage and transmission methods.

I would like you to describe figure 14 briefly.

In figure 14, we see that actual information does not change from one medium to the next. Easier transmission and copying of data is a significant part of computers' advancement and the creation of multi-billion dollars worth of various technology companies such as Google, Facebook, Twitter, etc. This is a major part of the computer revolution, perhaps even more important than computers' actual computing.

In this section, we covered

  • representations that computers understand
  • representing text, image & sound in binary
  • why binary is used for computers

The next section will look into how computers process instructions and information represented in the binary.