code (geek)

Category: Dreams and the Supernatural

Codes

I was reading this book Gödel Escher Bach, and a passing mention in the first chapter of how Gödel’s proof of his incompleteness theorem depended on encoding number theoretical statements as sequences of number, and was struck by the thought of how a concept which, only a hundred or two hundred years ago, occupied the greatest minds of their time, could find itself the plaything of an eight-year-old in the deepest darkest country woods of Texas.*

I’m talking about coding, the process of substituting one symbol with another. This process was not part of my initial experience with my first computer, because BASIC, the programming language it understood, did the simple coding required of the programs I wrote behind the scenes.

Pretty soon, however, I saw programs in 80 Micro that were written in “machine language”, the simple instructions that were natively understood by the computer’s microproccessor. The BASIC language I had written programs in before, for instance, was written in this machine language, and in turn provided a simpler and easier to use language for the computer’s user to write programs in.

Because computers only understand numbers, these machine language programs were just sequences of numbers themselves. And although the construction of these programs was an exercise in coding itself (since I had no “assembler” to do this encoding for me), one of the main issues I encountered in the course of writing these programs for myself is down to a simple fact: People don’t only communicate in numbers. In fact, most people regard numbers with a certain suspicion, as if they might at any moment attack and require the victim to multiply and divide and do other things with numbers that many people regard with dread.

So, in order to get computers to operate on letters and words, there must be a standard method for representing letters and words as numbers. My computer was set up so that there a set of memory locations, sort of buckets for numbers, such that for any number in one of the buckets, the computer’s hardware would convert to television signals, that, when displayed, formed a letter, number, or other symbol on the screen.

The coding by which the computer did this conversion is called ASCII (the American Standard Code for Information Interchange), and in modified form it persists in computers to this day. These very words that you are reading are stored in your computer’s memory as a series of numbers, according to these rules.

The rules are simple. Let us begin with a “string,” which is simply a series of symbols, such as letters, numbers, and punctuation, in a certain order. “DEADBEEF” is a string of eight letters, for example, and a sentence like “This is a string.” is a string as well.

ASCII divides a string into its constituent symbols, and then assigns a number from between 0 and 127 to each symbol. The uppercase letter “A”, for instance, is represented by the number 65; uppercase “B” is 66, and so on and so forth until the letter “Z” is assigned the number 90.

Because ASCII is designed to encode these symbols, or characters, for display, it must have different numbers for letters in different cases. Lowercase “a” begins at number 97; “b” is 98, and so on through “z”, which is assigned the number 121.

Because numbers must be displayed to the user in the same manner as text, there are also encodings for each of the decimal digits. “0″ is number 48, “1″ is 49, and so on through “9″, which is assigned number 57.

In combination with the specialized display hardware above, this encoding scheme allows us to display strings to the user. To write the string “This is a string.” on the screen, it is only necessary to store the number 84 (for “T”) in the memory bucket corresponding to the top left-hand position on the screen, and then 104 (for “h” in the next bucket to the right, then 105 (for “i”) to the right of that, then 115 (“s”) next, followed by 32 (which represents a space), and so on to the end of a string, where we store 46, which represents the period at the end of the sentence.

In this way, your computer communicates with you.

In a likewise fashion, every key you press on the keyboard stores an ASCII code for the key you pressed in a memory bucket, or location, which a computer program can later check.

Suppose you were writing a program to print out the total selling price of the user’s carrots, and requested from the user the number of carrots she had. You’re only dealing with whole carrots, and expect to get a whole number from the user.

But how do you verify that this is what the user typed? You can ask a user for any value you want, but you cannot trust the user to give you what you asked for. What if you asked for a number of carrots, and the user, in the grand tradition of lusers everywhere, typed “fifteen”?

When given a string of characters that the user has typed, such as “42″ or “eleventy-one”, it is difficult when thinking only of these characters to think of how to convey to the computer how to check to see if the string represents a number. However, by taking advantage of the encoding, this process becomes a lot simpler, and in fact this is among the simplest of computer programs to write. It all hinges on the definition of a whole number. For our purposes here, we’ll say that a whole number is represented by a string of characters, each of which is one of the digits from “0″ to “9″.

With the benefit of our standard coding, then, we can easily see that this is the same of saying that a whole number is a string of memory locations, each of which contains a number between 48 and 57.

All else we need to write this program is a variable, which is a memory location to which we have given a name. Once we have a name for this memory location, then we can read and write the values stored in it by name, and the program to determine whether a given string that the user has typed in becomes as simple as this:

1. Let the memory location we call IsANumber hold the number 1.

2. For each character in the string, check to see if the number in the corresponding memory location is smaller than 48 or larger than 57. If so, then store 0 in the memory location IsANumber.

3. If IsANumber is still 1 after checking all the characters, then the string is a whole number. If IsANumber is 0, then the string is not a whole number.

Any person with any training in computer programming can readily convert these instructions into a form a computer can understand, without the slightest need of any imagination, since we have already done the imaginitive work in designing the instructions.

As a final example, consider a program which takes some arbitrary string, such as “i am not shouting!” and converts all the letters in it to uppercase. In contrast to the three steps of the program above, this one is even simpler:

For each character in the string, check to see if the number in the corresponding memory location is higher than 97 (“a”), but lower than 121 (“z”). If so, then subtract 32 (which is “a”-”A”, or 97-65) and write the new number back to the memory location.

Following this process will convert “i am not shouting!” to “I AM NOT SHOUTING!”.

The computer you’re using right now runs these tiny little programs, or equally simple tiny programs, billions of times per second. The accumulative effect of all these tiny computations is the sum total of your computing experience.

That’s what I find fascinating about computers: that these tiny, simple building blocks, carefully assembled in their thousands and millions and billions, can enable such fascinating behavior as playing music or allowing lonely, lonely men to send dick pictures to women who post on Craigslist**.

*—i.e., me.

**—i.e., not me. I charge for my dick pictures.

Leave a Reply