ASCII

5 min read

Do you remember the Index term from the previous post? Now it’s time to show you a real-world example of how useful indexing can be.

Smart Usage of Numbers

At last, it’s time for some real action. Imagine two people, Anna and Mark, who have been given an important task: to send a text message over a network. Since this involves communication between two ends, Anna and Mark are on one end, while Joe and Jane are on the other. But how do they send the word HELLO? Can’t computers only speak in numbers? Yes, they can. But we, humans, are more advanced than that.

This problem was solved by Bob Bemer in 1961. He proposed a list of characters indexed using the DEC numbering system. On this list, each numeric Index is mapped to a character that is easily understandable by humans. This system was a huge step forward in standardizing data processing and communication between computers from different vendors. Let’s explore this list further.

Take a look at the ASCII table below. It contains all the necessary characters of the English alphabet. In the early 1960s, when computing was still in its infancy, this was more than enough. Today, we know how to store and process data in a unified manner using computers.

Please note that the first element in the list has an Index/Position equal to 0. As you may have noticed, our table starts with the exclamation mark and ends with the tilde, mapping to the range from 0 to 127. This is because the first 33 characters and the last one are non-printable, meaning they are used for control codes like tab or bell.

Helping Anna and Mark

Now, the guys need our help. Can you guess how we can send this message through the wire? I’m sure you can — it’s no big deal for you. What you need to do is look up the ASCII table for the four characters: H, E, L, and O. Don’t be confused by the different numbering systems in the ASCII table. They’re there to make your life easier. Have you noticed how often I mention making life easy? Yes, programmers are lazy by nature, and they don’t like repetitive tasks. That’s why many genius solutions exist.

Back to our message. If you look up the ASCII table, at Index = 72, you’ll get the letter H, which is the first letter of the message you’re about to send. Let’s find the rest of the numbers that map to the message.

CharacterIndexBIN
H7201001000
E6901000101
L7601001100
L7601001100
O7901001111

At last, the time has come for some fun. Below is an ASCII Messenger, an interactive transmitter and receiver. To send a character, just type the corresponding number and press the Send button on the transmitter panel. When done, it will appear on the receiver’s display. Try to help Anna and Mark transmit the message.

It was fun, right? Great job helping the guys. Now you have an idea of how we can send messages that are understandable by both humans and computers.

7 Bits of Surprise

Have you noticed that the BIN representation has only seven characters, not eight? Look at the ASCII Table at Index = 127. 127 is the largest number that can be represented with seven bits. We save one bit in every byte. Back in the 1960s, this was a big deal. Having one bit less means less work for processors, memory, and the network. While it may not matter when sending short messages like yours, when communicating with millions of devices, every bit matters.

More on Bytes

Our message in DEC is a sequence of five numbers: 72, 69, 76, 76, 79. Each number represents one byte, which has 8 bits. The order in which they are presented reflects the order of the letters in the message. But it’s not a rule — bytes can also be sent or written in reverse order. How? Let’s continue to the next section.

Bigger Numbers

So far, you’ve learned how to process values ranging from 0 to 127, but the needs are growing. We would like to map diacritics and letters from non-English alphabets so that the rest of the world can accept it as a standard. For this, we need much bigger numbers because there are many more characters to map. But how do we communicate with older machines that only support the ASCII table?

Words

If more space is needed for representation, how about adding another byte to the existing one? Thanks to this, we have something called a WORD. From now on, next to DEC and BIN, I’ll also use HEX notation, which is great for dealing with WORDS. Below is a table representing the same value, but decoded with three numbering systems. You’re already familiar with these.

BINHEXDEC
010010000x4872
010001010x4569
010011000x4C76
010011000x4C76
010011110x4F79

Hex gives us way more options for mapping than DEC. Thanks to this, much bigger numbers can be processed, meaning they can be stored, retrieved, or computed. Take a look at the HEX number sequences. They are placed in the same order as their BIN equivalents, so reading them is straightforward.

Earlier, I mentioned that byte order in a WORD (a collection of Bytes) may vary. Just like with bits, a WORD can be read from both left or right. This direction is called Endianess.

Endianess

The ordering of bytes in a WORD is called Endianess. This term was coined by Danny Cohen (a computer scientist) and introduced in 1980. Our DEC number 0x1234 is a WORD containing two bytes: 0x12 and 0x34. If the byte order is Big Endian, 0x12 is the Most Significant Byte (MSB), which is the first element of the sequence.

On the other hand, if the Little Endian ordering is used, 0x34 becomes the Least Significant Byte (LSB), and it goes to the last position in the sequence. Automatically, 0x12 becomes the Most Significant Byte.

OrderingMSBLSB
Big Endian0x120x34
Little Endian0x340x12

Summary

Now you know that bytes form words, which can have different ordering. You also have an understanding of how we prepare bits to process human-readable messages like “HELLO”.