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 |
→ I wrote 17 books to help you become a better developer:
- C Handbook
- Command Line Handbook
- CSS Handbook
- Express Handbook
- Git Cheat Sheet
- Go Handbook
- HTML Handbook
- JS Handbook
- Laravel Handbook
- Next.js Handbook
- Node.js Handbook
- PHP Handbook
- Python Handbook
- React Handbook
- SQL Handbook
- Svelte Handbook
- Swift Handbook
Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025