# Binary code

Binary code (or the binary system) is omnipresent in computer technology, and some people may still remember it from their math lessons. This code represents complex things with only two states. This is often difficult for people who are only familiar with the decimal system and its ten digits to understand. At the same time, binary code has its advantages and is also necessary to know about from a technical point of view.

## What is binary code?

Most people use the decimal system in which there are ten digits, ranging from 0 to 9. To express a large number, you add another “position”: so a number larger than the biggest digit in the decimal system, 9, needs a new position: “1”. Starting at the beginning we get position 1 plus the first digit of the decimal system “0”. These two digits together are displayed as 10, or “ten”. The binary system works in the same way. However, you only have **two digits** (or two states) available as the Latin prefix “bi” suggests: 0 and 1, on and off, light and dark, true and false. Just like in the decimal system, larger numbers are represented using more positions.

Binary code represents information by using only two different states.

People are generally familiar with the binary system in the context of computers where everything runs on ones and zeroes. This is how data is stored and computations are performed. However, this **method for computing and presenting information** is also used in other situations. Whenever we receive information through one of two states, this is basically binary code. A light on an electronic device can tell us whether it is running by being off (state 1) or on (state 2).

By stringing these on/off states together, you can communicate much more complex information. For example, the writing system for the blind **Braille** is based on binary code. In this system, each character is represented by a grid of six dots. The combinations of raised dots (1/on) and flat spaces (0/off) represents different characters.

## The history of the binary system: from Leibniz to computer systems

While binary code was already being used in classical antiquity to communicate information, the binary system as we know it today was not introduced until the end of the 17th century when it was conceived by **Gottfried Wilhelm Leibniz.** This philosopher and mathematician (and de facto generalist scholar) was looking for a method to convert logic terms (i.e. true and false) into a mathematical system and did so using the system of ones and zeroes still used today.

A few decades earlier, the English philosopher **Francis Bacon** had already begun to ponder how text could be represented using a binary code. A third scholar, **George Boole**, finally developed Boolean algebra based on the binary system about a century and a half after Leibniz. This system of logical operators is still very important in computer science today.

Similar systems were also developed in other parts of the world independently of these European breakthroughs in binary arithmetic, and sometimes much earlier. For example, the hexagrams in the Yi Jing (or I Ching) – a Chinese text from the 3rd century BC – are based on a binary code and refer to the duality of yin and yang.

In the 20th century, digital technology was finally developed, and the first electronic calculating machines were produced. It was the task of pioneers in computing to translate numbers and letters into a system which computers could understand. Binary code was made for this since the abstractions of 1s and 0s can be translated into **physical states**. For example, in electrical engineering, you can use 1 if there is voltage and 0 if there is no voltage.

**Punch cards** also use a binary system to communicate information. These cards can represent a certain number of characters using a hole or a lack of a hole. This allows information to be stored permanently and still be machine readable. Punch cards were already being used before computers were invented, such as with looms and mechanical music machines.

At first glance, binary code and binary system seem to be synonymous. However, once you understand what a code is, you will see the difference. A **code** is the controlled translation of characters. Each character in the original is assigned a different character or character string. This makes it possible to convert back and forth. Meanwhile, a system is self-contained and does not need to be compared to another system. For example, if you are computing using the binary system, you do not need to refer to the decimal system to get results.

Both can be found in electronic data processing (EDP). For example, this coding can be found in **ASCII code**. All letters in the Latin alphabet as well as some other characters can be represented with seven positions and two states (1 and 0). However, since this cannot represent anywhere near all the characters in the world, you can also use UTF-8 which uses one to four 8-bit bytes.

## Understanding binary coding: how does a computer work?

Computer systems recognize the unit’s **bits and bytes**. A bit is a position in the code which can be either a 1 or a 0. Its name is a portmanteau of “binary digit”. One byte is eight of these bits. Computers are basically calculating machines which work with these units, much like a calculator. To perform a calculation, decimal numbers are converted into the binary system.

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 1001 |

When thinking in terms of bytes, the decimal number 5 can be represented as follows: *00000101*. The **leading zeroes** at the beginning of the binary number do not affect the value and only ensure that a fixed format with eight positions is maintained.

In ASCII code, the digit 9 is represented as *0111001 *and 0 as *0110000.* This is due to the position of the digits in the code table.

As in the decimal system, **each position corresponds to a power**. However, unlike in our usual system which uses base 10 for calculations, the binary system uses base 2. The first position corresponds to 2^{0}, the second to 2^{1}, the third to 2^{2 }and so forth. A byte corresponding to the decimal number 23 can be read as follows:

2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |

0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |

Thus we have (decimal): 2^{4} + 2^{2} + 2^{1} + 2^{0} = 16 + 4 + 2 + 1 = 23

Calculations also work in the binary system similarly to the decimal system: 1100 + 1010 = 10110. What happens during the calculation? For simplicity’s sake, the addition can be structured in the same way as in a written calculation. You calculate from right to left.

- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 0 carry the 1

These calculations are standard for computers and are taking place all the time. Whether we are talking about PCs, smartphones, tablets or calculators, our commonplace digital tools could not exist without binary code.