Skip to main content

Section 1.4 Binary Numbers

90 minutes
Think about all the types of files and data that you store in your computer or phone. Whether you look at a photo or listen to a song or write a paper or play a game, all of that data is stored as bits, which are just 0’s and 1’s. It’s all bits! In this topic, you’ll learn how computers use bits to represent and process data.

Subsection 1.4.1 Data and Bits

Watch the following video to learn more about how computers use bits to represent data.

Subsection 1.4.2 Binary Numbers

Binary is a base-2 number system that uses only two digits, 0 and 1, to represent all numbers. Humans use the decimal number system, counting in base 10, probably because we have 10 fingers, but computers use the binary (base 2) number system to represent and process data because computer circuits only have 2 states, on and off, where 1 is on and 0 is off.
Watch this video from the Computer Science Unplugged, which illustrates how the binary number system works.
As you saw in the video, the students were simulating a binary odometer (like a car odometer counting miles) to count in binary.
Unplugged Activity: You and your friends can act out the video above by printing and using the following Binary Dot Cards. Five students can hold the 5 binary dot cards and see if they can count up from 0 to 11111. Or you can flip the cards randomly and see if the class can figure out the binary and the corresponding decimal number they make by counting the dots.
Try the binary odometer below.

Activity 1.4.1.

What is the next binary number after 1011? Try it out with the binary odometer above.
  • 1012
  • Binary numbers only use the digits 0 and 1.
  • 1111
  • This skips a few numbers. 1011 is 11 in decimal, and 1111 is 15. We are looking for the very next number (12 in decimal).
  • 1100
  • Correct! 1011 is 11 in decimal. Adding 1 triggers a carry to the next column twice resulting in 1100, which is 12 in decimal.
  • 10111
  • This increases the bit length unnecessarily. It shouldn’t require a 5th bit unless the original number was 1111.

Activity 1.4.2.

Activity 1.4.3.

AP 2021 Sample Question: Each student that enrolls at a school is assigned a unique ID number, which is stored as a binary number. The ID numbers increase sequentially by 1 with each newly enrolled student. If the ID number assigned to the last student who enrolled was the binary number 1001 0011, what binary number will be assigned to the next student who enrolls?
  • 1001 0100
  • Correct! Adding 1 to 1001 0011 causes the rightmost bits to carry over: 0011 + 1 becomes 0100, making the final value 1001 0100.
  • 1001 0111
  • Try again. Remember that adding 1 to a binary number will trigger carries wherever there is a 1, changing those 1s to 0s and carrying a 1 to the next left column.
  • 1101 0100
  • Try again. This changes bits in the first 4-bit group, which isn’t affected by adding 1 to this specific number.
  • 1101 0111
  • Try again. This changes bits that should remain unaffected and misses the proper carry operations on the rightmost bits.
Try the following Binary Converter. In pairs, have one partner click on the binary digits below to create a binary number, and have the other partner figure out the number as a decimal number (click on the ? button to check your the answer).

Activity 1.4.4.

What’s the largest number that can be represented in 4 bits? Try it out with the binary converter above.
  • 5
  • The number 8 in binary is represented as 1000. Additional numbers can be represented by turning some of the 0s into 1s. For example, the number 9 would be represented as 1001.
  • 12
  • The number 12 in binary is represented as 1100. Additional numbers can be represented by turning some of the 0s into 1s. For example, the number 13 would be represented as 1101.
  • 15
  • Yes. The largest number that can be represented in 4 bits would be 1111, which is 1 + 2 + 4 + 8, which equals 15.
  • 16
  • To represent 16 in binary, you would need 5 bits. It’s representation is 10000.

Activity 1.4.5.

Subsection 1.4.3 Abstraction

We use symbols like + and - in math or on a calculator to indicate arithmetic operations. This is another form of abstraction. For example, go to Google calculator and name the functions that are represented by the symbols on the buttons. For example, the symbol + represents the addition function, which takes two numbers as input and produces their sum as output.

Activity 1.4.6.

Activity 1.4.7.

Complete the following definition: An abstraction is a ____________ representation that stands for some collection of individual instances.
  • general
  • Yes. An abstraction is a general representation of something. Usually some of the specific details are omitted.
  • specific
  • Try again. A specific representation focuses on individual details, whereas an abstraction hides those details to look at the broader concept.
  • fixed
  • Try again. Abstractions can vary in their levels of detail and are not necessarily rigid or fixed.
  • artistic
  • Try again. While abstraction is a term used in art, in computer science and data context, it refers to a conceptual model rather than an artistic style.

Activity 1.4.8.

True or False: One of the main characteristics of an abstraction is that it simplifies a complex phenomenon by leaving out the irrelevant aspects.
  • True
  • Correct! Abstraction inherently manages complexity by focusing on essential details while hiding unnecessary complications.
  • False
  • Try again. One of the primary purposes of abstraction is to reduce complexity by filtering out details that aren’t necessary for the current context.

Activity 1.4.9.

Examples of abstraction can be found in which of the following? (Choose all that apply.)
  • Languages
  • Correct! Words abstract complex concepts or physical items into simple symbolic representations.
  • Designs
  • Correct! Blueprints and architectural designs abstract material details to emphasize layout and structural relationships.
  • Maps
  • Correct! Maps omit specific terrain details like individual trees or minor topography to cleanly illustrate routes and locations.
  • Computer science
  • Correct! Computer science relies heavily on layers of abstraction, from high-level programming languages down to binary logic gates.

Activity 1.4.10.

In Computer Science, the process of abstracting also means: (Choose all that apply.)
  • Complexing
  • Try again. Abstracting aims to achieve the opposite effect of making a concept more complicated.
  • Complicating
  • Try again. Abstracting reduces complexity rather than increasing it.
  • Condensing
  • Correct! Abstracting condenses information down to the most critical components required for high-level operations.
  • Simplifying
  • Correct! Abstracting simplifies systems so programmers and users do not need to understand low-level mechanical or digital technicalities.

Subsection 1.4.4 Encoding in Bits

For example, the binary code 01000001 can represent the decimal number 65 or the letter "A" in the ASCII encoding, or it could represent a pixel color in an image file, or a sound sample in an audio file, etc. The context of whether it is in a text file, image file, or audio file will determine what it means.

Activity 1.4.11.

The binary code 01000001 is just a sequence of 1s and 0s. Depending on the context of the file or the software interpreting it, which of the following could this sequence represent? (Choose all that apply.)
  • A decimal number like 65.
  • Correct! Mathematically, 01000001 in base-2 directly converts to 65 in base-10.
  • A large decimal number like 2,197,320,981
  • Try again. Eight bits won’t be enough to represent a large decimal number.
  • A letter like "A".
  • Correct! In ASCII encoding, the decimal value 65 maps directly to the uppercase letter "A".
  • A large text file that contains the contents of a book.
  • Try again. Eight bits won’t be enough to represent a large text file or a book.
  • A pixel color in a digital image.
  • Correct! In image file formats, sequences of bits correspond to color channel intensities (like Red, Green, or Blue levels).
  • A small sound sample in an audio file.
  • Correct! In digital audio files, binary numbers capture specific amplitude measurements of a sound wave at a given microsecond.

Subsection 1.4.5 Limitations of Binary Representation

When we try to store large numbers in a fixed number of bits, we may encounter roundoff errors. For example, the fraction 1/3 is a repeating decimal number 0.3333333333333333333333 with infinite 3’s after the decimal point. It cannot be represented exactly in binary with a finite number of bits. The computer will round the value to fit within the available bits as an approximation. A standard 32-bit floating-point number can only store seven 3’s after the decimal point safely (0.3333333). If this approximate number is used in further calculations, we can get results that are slightly off because of this roundoff error. For example, if we multiply 1/3 by 3, we would expect to get exactly 1, but due to the roundoff error in representing 1/3, we might get a result like 0.9999999 instead of 1. This illustrates how roundoff errors can lead to results that are close but not exactly correct.
An overflow error occurs when there aren’t enough bits to represent a given number, so some of them overflow. The number of bits is similar to how a glass can overflow if it’s filled with too much water.

Activity 1.4.12.

Which of following would cause an overflow error to occur. (Choose all that apply.)
  • Trying to represent 15 in 4 bits.
  • No, this would not cause an overflow. 15 is represented as 1111 in 4 bits.
  • Trying to represent 16 in 4 bits.
  • Yes. The largest number that can be represented in 4 bits is 15, which is 1111. To represent 16 you would need an additional bit, 1 0000.
  • Trying to represent 31 in 5 bits.
  • No, this would not cause an overflow. 31 is represented as 1 1111 in 5 bits.
  • Trying to represent 32 in 5 bits.
  • Yes. The largest number that can be represented in 5 bits is 31, which is 1 1111. To represent 32 you would need a 6th bit, 10 0000.

Activity 1.4.13.

True or False. Using a fixed number of bits to represent numbers limits the range of values and hence limits the range of problems that can be solved with that representation.
  • True.
  • Yes, to think of a simple example, if you were using 4 bits to represent numbers you wouldn’t be able to represent the number 17, so you wouldn’t be able to add 17 + 8. Modern computers use 32 or 64 bits to represent whole numbers, which are called integers. With 32 bits, you can represent \(2^{32}\) different values. That’s 4,294,967,296, more than 4 billion values. But, of course, there are still numbers that would cause overflow errors -- e.g., 4,300,000,000 could not be represented using 32 bits. This potential for overflow error is a necessary implication of using a finite representation to model the infinite concept of number.
  • False.
  • No. Using a fixed number of bits to represent numbers does limit the range of problems you can solve. For example, if you were using 4 bits to represent numbers you wouldn’t be able to represent the number 17, so you wouldn’t be able to add 17 + 8. Modern computers use 32 or 64 bits to represent whole numbers, which are called integers. With 32 bits, you can represent \(2^{32}\) different values. That’s 4,294,967,296, more than 4 billion values. But, of course, there are still numbers that would cause overflow errors -- e.g., 4,300,000,000 could not be represented using 32 bits. This potential for overflow error is a necessary implication of using a finite representation to model the infinite concept of number.

Subsection 1.4.6 Vocabulary Review

Activity 1.4.14.

You have attempted of activities on this page.