Binary Numbers: The Language of Data
students, every photo you send, every text message you read, and every video you stream is built from data that computers must store and process. One of the most important ideas in AP Computer Science Principles is that computers use binary numbers to represent that data. In this lesson, you will learn what binary numbers are, why computers use them, how to convert between binary and decimal, and how binary connects to the larger topic of Data in AP CSP. 💻🔢
What Binary Numbers Are
A binary number system uses only two digits: $0$ and $1$. Each digit is called a bit, short for binary digit. A group of $8$ bits is called a byte. Because computers are made from electrical circuits, binary is a natural fit: a circuit can easily represent two states, such as on/off or high/low voltage.
In the decimal system, which people use every day, there are $10$ digits: $0$ through $9$. In binary, each place value is a power of $2$ instead of a power of $10$. That means the rightmost bit is worth $2^0$, the next is worth $2^1$, then $2^2$, $2^3$, and so on.
For example, the binary number $1011$ means:
$$1\cdot 2^3 + 0\cdot 2^2 + 1\cdot 2^1 + 1\cdot 2^0 = 8 + 0 + 2 + 1 = 11$$
So $1011_2 = 11_{10}$. The subscript $2$ means binary, and the subscript $10$ means decimal.
Why computers use binary
Computers use binary because digital hardware is reliable when it only needs to distinguish between two states. If a voltage is above a certain level, the circuit may interpret it as $1$; if it is below, it may interpret it as $0$. This makes storage and processing more dependable than trying to use many different signal levels. Binary also works well with logic gates, which are the building blocks of computer processors.
A real-world example is a light switch. A switch can be off or on, which is similar to $0$ and $1$. Computers use incredibly small electronic switches called transistors, and billions of them work together to store and manipulate binary data.
Counting in Binary
Binary numbers follow a place-value pattern just like decimal numbers do. The difference is that each place is worth double the one before it. Here are the first few binary numbers and their decimal values:
$0_2 = 0_{10}$
$1_2 = 1_{10}$
$10_2 = 2_{10}$
$11_2 = 3_{10}$
$100_2 = 4_{10}$
$101_2 = 5_{10}$
$110_2 = 6_{10}$
$111_2 = 7_{10}$
$1000_2 = 8_{10}$
Notice the pattern: after $1_2$, the next number is $10_2$, not $2_2$, because there is no digit $2$ in binary. When a place value reaches its maximum, it resets to $0$ and the next place increases, just like carrying in decimal.
For example, if you add $1_2$ and $1_2$, the result is $10_2$. In decimal, this is $1 + 1 = 2$. Binary addition works similarly to decimal addition, but with fewer digits.
Converting decimal to binary
To convert a decimal number to binary, you can repeatedly divide by $2$ and record the remainders. Read the remainders from bottom to top.
Example: Convert $13_{10}$ to binary.
$13 \div 2 = 6$ remainder $1$
$6 \div 2 = 3$ remainder $0$
$3 \div 2 = 1$ remainder $1$
$1 \div 2 = 0$ remainder $1$
Reading the remainders upward gives $1101_2$. Check it:
$$1\cdot 2^3 + 1\cdot 2^2 + 0\cdot 2^1 + 1\cdot 2^0 = 8 + 4 + 0 + 1 = 13$$
This procedure is useful on the AP CSP exam because it tests your understanding of how binary encodes values.
Converting binary to decimal
To convert binary to decimal, multiply each bit by its place value and add the results.
Example: Convert $100101_2$ to decimal.
$$1\cdot 2^5 + 0\cdot 2^4 + 0\cdot 2^3 + 1\cdot 2^2 + 0\cdot 2^1 + 1\cdot 2^0$$
$$= 32 + 0 + 0 + 4 + 0 + 1 = 37$$
So $100101_2 = 37_{10}$.
A good check is to make sure the highest power of $2$ matches the leftmost $1$.
Binary and Representing Data
Binary numbers are not only used for counting. They are used to represent many kinds of data, including text, images, audio, and instructions.
Text
Computers store letters, numbers, and symbols using binary code. For example, each character can be assigned a number, and that number is stored in binary. Modern systems use standard encodings such as ASCII and Unicode. ASCII uses $7$ bits for common characters, while Unicode can represent many more characters from different writing systems.
Example: The capital letter $A$ is represented by the decimal value $65$ in ASCII, which is $1000001_2$ in binary.
Images
Images are often made of tiny dots called pixels. Each pixel can be represented using binary values for color information. For a black-and-white image, a $0$ might mean black and a $1$ might mean white. For color images, groups of bits can represent red, green, and blue values. More bits allow more possible colors and smoother detail.
Audio
Sound can be recorded by measuring air pressure many times each second. Each measurement is converted into binary. Higher sampling rates and more bits per sample usually produce better sound quality, because the computer has more precise data to work with.
Instructions and programs
Computer programs are also stored as binary at the hardware level. Even though humans write code in languages like Python or Java, the processor ultimately executes binary machine instructions.
This shows how binary fits into the broader AP CSP idea of Data: data can be stored, transformed, transmitted, and interpreted in many forms. Binary is the core representation that makes those processes possible.
Information, Precision, and Limits
Binary is powerful, but it has limits. A fixed number of bits can only represent a limited number of values. For example, with $3$ bits, there are only $2^3 = 8$ possible combinations, from $000_2$ to $111_2$. That means only $8$ different values can be stored with $3$ bits.
This matters in real life. If an image uses too few bits for color, it may look blocky or show banding. If audio is stored with too few bits per sample, it may sound less accurate. If a number is too large for the available bits, the value may overflow, meaning it cannot be represented correctly in that space.
Binary also affects efficiency. More bits can improve precision, but they use more storage and bandwidth. That is why designers make trade-offs between quality, size, and speed.
For AP CSP, this is an important reasoning skill: data representation always involves a balance between accuracy and resource limits.
Practice Example for AP CSP Reasoning
Suppose a device uses $5$ bits to represent a value. How many distinct values can it represent?
Since each bit has $2$ possible states, the total number of combinations is:
$$2^5 = 32$$
So the device can represent $32$ distinct values, from $00000_2$ to $11111_2$.
Now suppose the binary number is $01101_2$. What decimal value is it?
$$0\cdot 2^4 + 1\cdot 2^3 + 1\cdot 2^2 + 0\cdot 2^1 + 1\cdot 2^0 = 0 + 8 + 4 + 0 + 1 = 13$$
These kinds of questions test your ability to interpret binary values and reason about representation.
Conclusion
students, binary numbers are the foundation of digital data representation. Computers use $0$ and $1$ because hardware can reliably store two states, and those bits combine to form bytes, characters, images, audio, and instructions. Understanding place value in powers of $2$, converting between binary and decimal, and recognizing the limits of fixed bit lengths are essential AP Computer Science Principles skills. Binary is not just a math topic; it is a core part of how computers store, process, and communicate data. 🚀
Study Notes
- Binary uses only the digits $0$ and $1$.
- A single binary digit is a bit.
- $8$ bits make $1$ byte.
- Binary place values are powers of $2$, such as $2^0$, $2^1$, $2^2$, and so on.
- To convert binary to decimal, multiply each bit by its place value and add.
- To convert decimal to binary, divide by $2$ repeatedly and read remainders from bottom to top.
- Computers use binary because digital circuits reliably represent two states.
- Binary is used to represent text, images, audio, and machine instructions.
- More bits allow more possible values and greater precision.
- A fixed number of bits limits how many values can be represented.
- Binary is a major part of the AP CSP topic Data and helps explain how information is stored and processed.
