Back to Mathematical Foundations
IntermediateTeenagers
Binary Numbers
Computers don't think in the numbers we use (0-9). They think in **binary**, which only uses two digits: 0 and 1. Everything a computer does, from showing a picture to running a game, is broken down into a series of 0s and 1s.
Our number system is "base-10" because we have 10 digits. Binary is "base-2".
Let's see how it works. In base-10, each place value is a power of 10:
... 1000s, 100s, 10s, 1s
In binary, each place value is a power of 2:
... 16s, 8s, 4s, 2s, 1s
So, the number 5 in binary is
-
-
-
- 4 + 0 + 1 = 5
The number 10 in binary is
-
Understanding binary is key to understanding how computers work at their most fundamental level.
Our number system is "base-10" because we have 10 digits. Binary is "base-2".
Let's see how it works. In base-10, each place value is a power of 10:
... 1000s, 100s, 10s, 1s
In binary, each place value is a power of 2:
... 16s, 8s, 4s, 2s, 1s
So, the number 5 in binary is
101. Why?-
1 in the 4s place = 4-
0 in the 2s place = 0-
1 in the 1s place = 1- 4 + 0 + 1 = 5
The number 10 in binary is
1010.-
1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 = 10.Understanding binary is key to understanding how computers work at their most fundamental level.
Binary to Decimal
Create a function `binary_to_decimal` that takes a string representing a binary number (e.g., "101") and returns its decimal (base-10) equivalent.