Binary is a number system that uses only two digits, 0 and 1 — compared to the decimal system you use every day, which has ten digits (0–9). It's the number system computers use internally, because a bit only has two possible states.
In decimal, each position represents a power of 10 (1, 10, 100, ...). In binary, each position represents a power of 2 (1, 2, 4, 8, ...).
| Binary | Calculation | Decimal |
|---|---|---|
| 0000 | — | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 2 + 1 | 3 |
| 0100 | 4 | 4 |
| 1010 | 8 + 2 | 10 |
let decimal = parseInt("1010", 2);
console.log(decimal); // 10let binary = (10).toString(2);
console.log(binary); // "1010"