Encoding & Decoding

A byte just represents a number. What does that number mean or represent, though?

If one byte can represent up to 256 different numbers, and can be expressed in either binary or hexadecimal, how do we use those numbers to represent different things? We have to encode the numbers, which means to translate or convert them into a specific format. Similarly, we can decode those specific formats back into numbers, which can then be represented by binary or hexadecimal.

Common Types of Encoding

  • Instruction encoding - Encoding used to convert numbers into instructions that a computer's processor can understand and execute.
  • Character encoding - Encoding used to convert numbers into printable characters, like numbers, letters, and special characters.
  • Digital Image encoding - Encoding used to convert numbers into Red, Green, and Blue (RGB) values for pixels on a screen.
  • Analog-to-Digital Audio encoding - Encoding used to convert numbers into a vertical range of amplitudes.

One number can be encoded into many different things, like an instruction for a processor, a special character, or a value for Red, Green, or Blue, on a computer's screen.

Instruction Encoding

Instruction Set Architecture (ISA) is a set of instructions that can be carried out by the CPU, and includes instructions and operands. Instruction operands describe data values manipulated by the instruction. One very common ISA is Intel's x86 micro-architecture and its instruction set.

Character Encoding

We know that we can represent a large number of states using many bits as seen above. If we wanted to represent a number (like 9), or a letter (like 'C'), or a character (like '$'). How would we do that?

Simply, we would just assign a number to represent a one of these things. We could say that 'A' would equal 0, 'B' would equal 1, 'C' would equal 3, and so on and so forth. However, an issue arises pretty early on by doing this as there are a total of 26 different letters in the American alphabet (and each letter needs to be represented in both lowercase and uppercase), bringing the total number of possible characters to 52, but that doesn't include any additional characters like '@', '?', or '%'.

We quickly realize that we can't represent all of these characters with just four bits, as four bits can only give us sixteen possible states, so we need to add an additional four bits, giving us a total of 256 possible states. In other words, we can assign the whole alphabet (both lowercase and uppercase letters), the different punctuation marks, and all special characters, to a particular number using just eight bits.

Eight bits together are powerful and can let us represent numbers, characters, and special characters - the smallest possible form of data. We refer to eight bits together as one byte. A computer's CPU cannot address anything smaller than a byte.

How do we know what characters should be assigned to what number? Well, in order for a computer to encode (the process of assigning numbers to character) a number (like 65) to a character (like 'A'), and then for the computer to decode the number (65 means 'A'), there needs to be a set standard that is agreed on by many, so this communication can be used across computers with no issue.

That's where the American Standard Code for Information Interchange (ASCII) comes in. ASCII is a character table that primarily uses 128 numbers (7-bit) to represent different numbers, letters, and characters, as well as thirty-two non-printing characters (like null, new Line, tab, and space). There is an extended ASCII character table that uses 256 numbers (8-bit). There is also a standard called The Unicode Standard (Unicode for short) that is managed by the Unicode Consortium. Unicode includes all the characters that can be encoded in ASCII, plus many more. While ASCII is useful for representing characters in the English language, Unicode is capable of representing a much wider range of characters in other languages and scripts.

ASCII states that the capital letter 'G' is assigned to the number seventy-one. In binary, seventy-one would appear like 01000111. Every time the computer process 01000111, it will print the capital letter G on the screen.

Digital Image Encoding

Analog-to-Digital Audio Encoding