Electronics Basics: Analog vs digital
We divide electronics into 2 big parts: analog and digital.
Everything in the natural world is analog.
Temperature, light, distance, speed, humidity, sound, everything is measured in a nearly infinite amount of values and precision.
Analog is natural. Digital, however, is artificial. Humans, in their ancestral quest to understand nature and create artificial systems and simulations, came up with the concept of digital measurements and values.
A digital representation can only assume 2 states: on or off. 1 or 0.
Representing basic values using only 0 and 1 values made it possible to solve complex problems in a simple way, and eventually led us to creating things like our computers, smartphones and the Internet.
We can combine multiple binary values to represent numbers that have more than 2 states. With 2 numbers we can define 4 states, with 3 numbers 8, with 4 numbers 16, and so on.
Then we use specific protocols and conventions to represent values.
For example we can represent decimal numbers using a series of bits:
1 can be represented as \[1\times2^0\]
10 can be represented as \[1\times2^1 + 0\times2^0\]
111 can be represented as \[1\times2^2 + 1\times2^1 + 1\times2^0\]
Leading zeros in a number can be dropped, or added if needed, because they do not mean anything on the left of the top left 1: 110 can be represented a 0110 or 00000110 if needed. It holds the same exact meaning, because as the system above explained, we are simply multiplying a power of 2 times zero.
Depending on the value we need to represent we need to have an adequate number of digits to represent enough numbers.
If we want to have 16 values, so we can count from 0 to 15, we need 4 digits (bits). With 5 bits we can count 32 numbers. 32 bits will give us 4,294,967,296 possible numbers.
64 bits will give us 9,223,372,036,854,775,807 possible numbers.
Here is a simple conversion table for the first 4 digits, which we can generate using just 2 bits:
| Decimal number | Binary number | 
|---|---|
| 0 | 00 | 
| 1 | 01 | 
| 2 | 10 | 
| 3 | 11 | 
Here is a simple conversion table for the first 8 digits:
| Decimal number | Binary number | 
|---|---|
| 0 | 000 | 
| 1 | 001 | 
| 2 | 010 | 
| 3 | 011 | 
| 4 | 100 | 
| 5 | 101 | 
| 6 | 110 | 
| 7 | 111 | 
If you notice, I repeated the above sequence, adding 1 instead of 0 in the series from 4 to 7.
Here is a simple conversion table for the first 16 digits:
| Decimal number | Binary number | 
|---|---|
| 0 | 0000 | 
| 1 | 0001 | 
| 2 | 0010 | 
| 3 | 0011 | 
| 4 | 0100 | 
| 5 | 0101 | 
| 6 | 0110 | 
| 7 | 0111 | 
| 8 | 1000 | 
| 9 | 1001 | 
| 10 | 1010 | 
| 11 | 1011 | 
| 12 | 1100 | 
| 13 | 1101 | 
| 14 | 1110 | 
| 15 | 1111 | 
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.