Binary code: how does a computer add 6 and 7 when it only knows how to turn it on and off

Executive Briefing
Synthesized and verified with gemini-2.0-flash-thinking-exp
“Inside every phone there are billions of tiny switches, each of which only knows two things: let ele”
Key Takeaways
- 1.Inside every phone there are billions of tiny switches, each of which only knows two things: let electricity pass through or block it.
- 2.Yet from those switches, the computer can do all calculations.
- 3.The secret lies in two things: the way numbers are written using only 0 and 1, called the binary system, and small circuits called logic gates that turn electrical currents into calculations.
Inside every phone there are billions of tiny switches, each of which only knows two things: let electricity pass through or block it. Yet from those switches, the computer can do all calculations. The secret lies in two things: the way numbers are written using only 0 and 1, called the binary system, and small circuits called logic gates that turn electrical currents into calculations.
Count with two fingers
The decimal system has ten digits from 0 to 9. If greater than 9, add one digit to the left. The binary system does the same thing but only has two digits, 0 and 1. Counting up will give you 0, 1, then you run out of digits so you have to write 10, followed by 11, 100, 101 and so on. In the decimal system, each place is worth ten times the place to the right of it, and in the binary system it is twice as valuable: 1, 2, 4, 8, 16. The number 13 is written as 1101, meaning one 8, one 4, no 2 and one 1.
Each binary digit is called a bit. According to HowStuffWorks, computers use this system because it is much easier to make with electronic components than the ten-digit system. Eight bits combined into one byte, enough to record 256 values, from 0 to 255.
How to count using the binary system, 6 + 7 addition written in binary style and a partial adder consisting of two logic gates XOR and AND
The idea dates back to the 17th century
According to Wikipedia, the person usually credited with inventing the modern binary system is Gottfried Wilhelm Leibniz, although Thomas Harriot had researched it before. Leibniz left behind more than a hundred manuscripts on this subject. In 1679, he wrote the first article showing how to convert decimal numbers to binary and how to add, subtract, multiply, and divide with numbers consisting of only 0 and 1. The most famous article, Explication de l'Arithmétique Binaire, was published in 1703.
A page of Leibniz's handwritten notes on the binary system, kept at the Gottfried Wilhelm Leibniz Library (Hannover): the left column is 1, 10, 100, 1000..., the right column is 1, 2, 4, 8... respectively
In 1854, British mathematician George Boole published an algebraic system for logic with only two values, true and false, today known as Boolean algebra. In 1937, Claude Shannon wrote his master's thesis at MIT, first using relays and electrical switches to perform Boolean algebra and binary arithmetic, laying the foundation for digital circuit design.
Logic gates: decision-making switches
A logic gate is a small circuit that receives one or several 0 and 1 signals, then outputs a signal according to a fixed rule. HowStuffWorks lists three basic spells:
- AND: only outputs 1 when both inputs are 1.
- OR: output 1 when at least one input is 1.
- NOT: reverse the signal, input 1 then output 0 and vice versa.
Adding an XOR gate, which indicates 1 when the two inputs are different, is enough material for addition. In electronic circuits, the number 1 usually corresponds to a high voltage level, the number 0 corresponds to a low voltage level.
Add 1 to 1 equals two gates
Advertisement
Binary addition has only four cases: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1 and 1 + 1 = 10, that is, write 0 and remember 1 in the left column. If you look closely, you will see that the resulting digit is only equal to 1 when the two numbers are different, which is true for the XOR gate. The carry number is only 1 when both are 1, which is true for AND gates. Putting an XOR gate and an AND gate next to each other, given the same two inputs, we get a two-bit adder circuit called a half adder.
To add multi-digit numbers, each column must also add the remembered number from the right column. According to Wikipedia, combining two half adders with an OR gate will result in a full adder, receiving three input bits. Connecting many such sets into a series, the memory passes from one column to the next, the computer can add 8, 16, 32 or 64 bit numbers. For example, 6 + 7 is written as 0110 + 0111, giving 1101, which is exactly 13.
A reconstruction of the Model K adder made by George Stibitz himself in 1980, displayed at the Computer History Museum (USA). The original was assembled on the kitchen table from discarded Bell Labs relays and metal pieces cut from cans
From the kitchen table to the chip
One of the first electric binary adders appeared on the kitchen table. According to the Computer History Museum (CHM), George Stibitz, then working at Bell Labs, used discarded relays from the laboratory and metal pieces cut from cans to assemble a binary two-digit addition circuit, named Model K, the letter K taken from kitchen. CHM records the year 1936, while Wikipedia records November 1937. This circuit leads to Bell Labs' Complex Number Calculator, in operation since 1940.
Stibitz's mechanical relays today have given way to transistors located on chips. However, the principle remains the same: numbers are written with 0 and 1, and addition is done by XOR, AND, OR gates connected together.
Advertisement
Attribution & Original Source
Synthesized and verified from Tinhte.vn. All copyrights and intellectual property belong to the original publication.