Data / LESSON 03

Reading bit patterns as values and abstractions · AP Computer Science Principles

10 min + practice · Original foundation lesson

Convert between binary and decimal using place values, and explain what a fixed number of bits can and cannot represent.

Core ideas and conditions

Computing devices store all data as sequences of bits, where each bit is a 0 or a 1, and eight bits form a byte. The same sequence of bits can mean different things in different contexts: one program may read a byte as an unsigned integer while another reads it as a character code or part of a color, because interpretation is applied by the reading program rather than carried by the bits themselves. Binary is base 2 and decimal is base 10, and in both systems a digit’s value comes from its place value, which is the base raised to the power of its position counting from 0 at the right. Converting binary to decimal therefore means adding the place values under the 1-bits, and converting back means subtracting the largest place value repeatedly.

Worked example: convert 100110 in both directions

Draw the place row for six bits: 32, 16, 8, 4, 2, 1. Under 100110 the 1-bits sit in the 32, 4 and 2 places, so the decimal value is 32 + 4 + 2 = 38. For the reverse direction, convert 22 to binary by subtracting the largest place value repeatedly: 22 - 16 = 6, then 6 - 4 = 2, then 2 - 2 = 0, so 1-bits go in the 16, 4 and 2 places and 22 reads 10110. Finish every conversion by checking the result in the other direction; one misplaced place changes which powers of two appear in the total, and the check exposes it immediately.

Fixed bits, range limits and the same bits reused

A fixed number of bits limits what can be represented: n bits form exactly 2^n patterns, and as unsigned integers those patterns name 0 through 2^n - 1. Eight bits give 256 patterns covering 0 to 255, and each added bit doubles the count; the maximum is one less than the pattern count because 0 occupies a pattern. When a computation produces a value beyond the maximum, the result cannot be represented and an overflow error occurs. This limit also explains why the same bits can serve different purposes: nothing about the pattern fixes its meaning, so the meaning must come from the context that reads it.

Transfer check: size a score field

A device stores one progress level ranging from 0 to 100 as an unsigned integer. Before reading on, decide the minimum number of bits and justify the choice. Six bits give 2^6 = 64 patterns, naming 0 through 63, so 100 does not fit; seven bits give 128 patterns naming 0 through 127, so 7 is the minimum that works. Then explain, using no new facts, why a different program could read those same 7 bits as something other than a number. You have completed this check when you can state the pattern count, the maximum value, and the role of context in one sentence each.

Try it, then explain it.

Complete a short set without looking at the example. After each answer, explain which evidence or rule supports your decision and why the alternatives do not fit.

Practice 3 questions

Sources & authorship

Original OpenExam explanations and examples. References support the concepts; they are not the source of copied questions. Independent educator review is pending.

AP Computer Science Principles Course and Exam Description (CED)