# Lesson 01

### What Language Do Computers Speak?

What languages do computers speak?  Do they speak English? In today’s world, it is tempting to say yes.  After all, we talk to Siri, Alexa and Google Assistant. But no, computers do not speak in English.  We are able to speak to our computers because someone wrote software to listen to us speak, and convert that into commands for the computer to execute.

Since we are taking a computer programming class and learning Smalltalk, perhaps that is the language of computers?  Or any other programming language such as Perl, Python, C++, Ruby, Java (the list is very, very, very long…). However, these guesses would also be wrong.  In order for the computer to understand our programs, we again need software to “translate” our programs. Depending on the language, this software is called a compiler, an interpreter or a virtual machine.  Squeak, is the virtual machine we will use to translate our Smalltalk programs into something the computer can understand.

Computers speak in Binary.  Binary is a number system consisting of just ones and zeroes arranged in patterns.  These patterns are not random, but represent numbers that can be converted into numbers, letters, sounds, colors and all the many different things we experience with computers.  So let us take a quick look at the binary numbering system.

The number system we are all most familiar with is called Decimal, or Base 10.  It has this name because it has ten different digits used to represent numbers. Those digits are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.  So if our numbering system has ONLY ten digits, how do we represent numbers larger than that? Well we have to add those digits up. To represent larger numbers, we write special equations like: 238.

238?  An equation?  Why yes, in fact it is.  Let us look at what we know about our number again, but from a slightly different perspective.  As you can see, 238 is not one digit or character, it is three different digits, all of which come from our Base 10 numbering system.  What makes this arrangement of numbers meaningful is how they are arranged.

For example, the digit 8 is in what we call the “ones” column.  That means we take whatever is in that column and multiply it by ‘1’.  In this case, we have 8*1 = 8.

The digit 3 is in the “tens” column and so we multiply it by 10, or 3*10 = 30.

Finally, the 2 is in the “hundreds” column and is thus 2*100 = 200.  To get our final value, we add all three of these up.

So the “number” 238 is actually a shorthand representation for:

(2*100) + (3*10) + (8*1)

Now let us change this up just a little bit more.  Since our number system is Base 10, let us rewrite the above equation in terms of 10s.

(2 *10*10) + (3*10) + (8*1)

Why did we do this?  Because we want to rewrite it one more time, using another special format.  Ask yourself, how many “10s” are there in the first part of the equation? There are two of course, so rewrite 10*10 as 102.  In the second part of the equation, we have only one 10, so write that as 101.   Finally, in the last part, we have zero 10s so we write that as 100.  Using this new notation, we convert the above equation to:

(2*102) + (3*101) + (8*100)

It is not really that important to fully understand exponents other than to accept it as a quirky format to represent how many times you multiply the big number by itself.  Thus:

100 = 1
101 = 10
102 = 10 * 10 = 100

This brings us to Binary or Base 2.  If Base 10 has ten digits, how many digits does Base 2 have?  The correct answer is, of course, just two. Those digits are 0 and 1.  So how do we represent values larger than 1? We do it the same we do with decimal numbers.  We write “equations.” If we use the same mechanism as above, we know the following:

20 = 1  (because anything to the zero power is 1)
21 = 2
22 = 2*2 = 4
23 = 2*2*2 = 8
24 = 2*2*2*2 = 16 

Knowing this, we can write the same numbers we know in decimal, using only a string 1s and 0s!  Let us examine this more closely. Take the binary number 0101.

The first column is our “ones” column and is therefore 1*1 = 1.

Our second column is our “twos” (NOT tens!) column and is 0*2 = 0.

Our third column is our “fours” column and is 1*4 = 4.

Our last column is our “eights” column and so is 0*8 = 0.

Adding them all up, we get:

0101 = (0*8) + (1*4) + (0*2) + (1*1) = 0 + 4 + 0 + 1 = 5

Just like decimal, the more digits used to represent the number, the bigger it gets.  The only difference is binary has only two digits to choose from, and each column value is increased by multiplying it by another 2.  You can even add binary numbers, the same way you add decimal numbers!

010111
000010
------

If we add the digits in the far right column first (just like we would do with decimal numbers) we get 1+0 = 1

010111
000010
------
1

Adding the digits in the second column we get 1+1 = 2.  But remember, we can only use the digits 0 and 1. So how do we write 2 in binary?  Looking back up above, we see we would write decimal 2 as binary 10. Remember, this is the same as saying (1*2) + (0*1).  So what do we do with a number in decimal when the digits added are two digits long (greater than 9).  Why we put the second digit down below and “carry the one” giving us the following:

   1
010111
000010
------
01

Repeating the process for column three, we now add the 1 we carried over to the 1 already there and the 0 below that to get 1+1+0 = 2 or, as above, 10.  So again, the 0 goes below and we carry the 1.

  11
010111
000010
------
001

Repeating for column four, we get 1+0+0 = 1 (whew! An easy one!).

  11
010111
000010
------
1001

For column five, we get 1+0 = 1 and for column six we get 0+0 = 0, leaving us with our final answer of:

  11
010111
000010
------
011001

So, let us be brave and check our answers.  What does binary 010111 equal in decimal? Using our chart above, convert as follows:

(0*25) + (1*24) + (0*23) + (1*22) + (1*21) + (1*20)

Converting that to a more familiar format we get:

(0*2*2*2*2*2) + (1*2*2*2*2) + (0*2*2*2) + (1*2*2) + (1*2) + (1*1)
0       +     16      +     0     +    4    +   2   +   1 = 23

Our second number, 000010 would then be:

(0*2*2*2*2*2) + (0*2*2*2*2) + (0*2*2*2) + (0*2*2) + (1*2) + (0*1)
0       +      0      +     0     +    0    +   2   +   0 = 2

Finally, our answer, 0110001 would be:

(0*2*2*2*2*2) + (1*2*2*2*2) + (1*2*2*2) + (0*2*2) + (0*2) + (1*1)
0       +     16      +     8     +    0    +   0   +   1 = 25

Since 23+2 does indeed equal 25, we can see our binary math was correct.

So why am I telling you all this?  Because that is how computers work. EVERYTHING a computer does is a math problem!  You might even say, it “COMPUTES” every command you give it, into something else to respond back to you.

Next we will do an experiment with a series of lights to show how a computer represents something simple, in binary.