Binary Numbers
The Language of Computers
Learn how computers represent all data using just two digits: 0 and 1. Master conversions between binary and decimal systems.
What is Binary?
Binary is a base-2 number system that uses only two digits: 0 and 1. Every piece of data inside a computer: numbers, text, images, audio, and video: is ultimately stored as a sequence of binary digits, called bits.
Why Do Computers Use Binary?
Computer hardware is built from billions of tiny transistors: electronic switches that are either on or off. Binary maps perfectly to this physical reality.
Decimal vs Binary Systems
The decimal system you use every day is base-10: it uses digits 0 through 9, and each place value is a power of 10. Binary works the same way, but each place value is a power of 2.
Place values: \(\ldots, 10^2, 10^1, 10^0\)
Place values: \(\ldots, 2^2, 2^1, 2^0\)
The Place Value System
Each position in a binary number corresponds to a power of 2. The rightmost position is \(2^0 = 1\), and each position to the left doubles in value.
Binary to Decimal Conversion
To convert a binary number to decimal, multiply each bit by its place value and add the results together.
= 1 × \(2^3\) + 0 × \(2^2\) + 1 × \(2^1\) + 1 × \(2^0\)
= 8 + 0 + 2 + 1
= 11 in decimal
Decimal to Binary Conversion
To convert a decimal number to binary, repeatedly divide by 2 and record the remainders. Read the remainders from bottom to top.
Comparing Number Systems
| Property | Decimal | Binary | Hexadecimal |
|---|---|---|---|
| Base | 10 | 2 | 16 |
| Digits Used | 0 – 9 | 0 – 1 | 0 – 9, A – F |
| Example: 255 | 255 | 11111111 | FF |
| Used By | Humans | Computers | Programmers |
| Place Values | \(10^n\) | \(2^n\) | \(16^n\) |
Step-by-Step Conversion Checklist
2. Multiply each bit by its place value
3. Add all the products together
2. Divide quotient by 2, write remainder
3. Repeat until quotient is 0
4. Read remainders bottom-to-top
Example 1: Convert 10110 to Decimal
= 16 + 0 + 4 + 2 + 0
= 22
Example 2: Convert 45 to Binary
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← MSB
Example 3: Convert 11001010 to Decimal
Binary Addition
Binary addition follows the same rules as decimal addition, but carrying happens at 2 instead of 10.
\(0 + 1 = 1\)
\(1 + 0 = 1\)
\(1 + 1 = 10\) (write 0, carry 1)
+ 0110 (6)
————
10001 (17)
Understanding Overflow
When a binary number exceeds the available number of bits, an overflow occurs. The extra bit is lost, producing an incorrect result.
Common Mistakes to Avoid
Powers of 2 Reference Table
| Power | Decimal Value | Binary | Bits Needed |
|---|---|---|---|
| \(2^0\) | 1 | 1 | 1 |
| \(2^1\) | 2 | 10 | 2 |
| \(2^2\) | 4 | 100 | 3 |
| \(2^3\) | 8 | 1000 | 4 |
| \(2^4\) | 16 | 10000 | 5 |
| \(2^7\) | 128 | 10000000 | 8 |
| \(2^8\) | 256 | 100000000 | 9 |
| \(2^{10}\) | 1024 | 10000000000 | 11 |
Question 1 of 5
What is the decimal value of the binary number 1101?
Question 2 of 5
What is 42 in binary?
Question 3 of 5
What is the maximum decimal value that can be represented with 6 bits?
Question 4 of 5
What is the result of adding the binary numbers 1011 and 0101?
Question 5 of 5
A computer uses 4 bits to store an unsigned integer. If the current value is 1111 and you add 1, what happens?