Computer Science and Problem Solving
How Computers Represent Data
Computer science and problem solving
Computer science can be understood as a collection of ideas and techniques used to solve problems. A computer receives an input, processes it using instructions and methods, and produces an output.
Input: The problem or information supplied to the computer.
Processing: The operations the computer performs on the input, using instructions and techniques.
Output: The result or goal produced by processing.
Problem solving follows the same pattern: identify a problem, apply suitable ideas and techniques, and produce a result. Data structures and algorithms are among the tools used to solve computational problems.
Transistors, electrical states, and bits
A computer contains enormous numbers of transistors, electronic components that can act like switches. In a simplified model, each transistor has two states:
ON: An electrical signal is present.
OFF: An electrical signal is absent.
Computers encode these two states using the digits 1 and 0:
1 represents ON.
0 represents OFF.
A bit (short for binary digit) is one unit of information that can represent either 0 or 1. At this introductory level, a bit can be thought of as recording the state of one transistor.
A bit has two possible values: 0 or 1. By combining bits, a computer can represent many more values than either digit can represent alone.
This is why computers are often said to “understand zeros and ones.” Their electronic circuits work with distinguishable signal states, which are represented logically as binary digits. Real hardware uses electrical behavior more precisely than a simple ON/OFF switch, but the two-state model is useful for understanding how data is encoded.
Combining bits creates more possibilities
Each bit has two possible states. Adding more bits increases the number of possible combinations:
One bit: 2 combinations: 0, 1.
Two bits: 4 combinations: 00, 01, 10, 11.
Three bits: 8 combinations.
Four bits: 16 combinations.
For n bits, the total number of possible combinations is:
This occurs because each bit has 2 choices, and the choices are independent. For example, three bits have 2×2×2=23=8 possible patterns.
The total number of combinations is not the same as the largest number represented. When the combinations are used to represent nonnegative integers starting at zero, n bits represent the values from 0 through 2n−1. Thus, the largest value is:
For example:
Three bits provide 23=8 combinations, representing 0 through 7.
Four bits provide 24=16 combinations, representing 0 through 15.
Binary numbers and counting
A binary number is a number written using only the two digits 0 and 1. The word binary means “two-based.” The sequence below shows how three bits represent the values from 0 through 7:
000 represents 0.
001 represents 1.
010 represents 2.
011 represents 3.
100 represents 4.
101 represents 5.
110 represents 6.
111 represents 7.
The same counting pattern extends to any number of bits. In the bulb analogy, an ON bulb represents 1 and an OFF bulb represents 0. Each new arrangement of ON and OFF states represents a different binary pattern, and each pattern can be assigned a number.
How binary counting advances
Binary counting changes patterns according to these rules:
Begin at the rightmost bit, which changes most often.
If that bit is 0, change it to 1.
If it is already 1, change it to 0 and carry the change one place to the left.
Continue carrying left through any consecutive 1s. The first 0 encountered becomes 1.
If every bit is already 1, all existing bits reset to 0 and an additional bit is needed to represent the next value.
For example, the three-bit pattern 011 represents 3. Adding one changes the rightmost 1 to 0, then carries left: the next 1 also becomes 0, and the leftmost 0 becomes 1. The result is 100, which represents 4.
When a new, more significant bit is added, the earlier bits reset to zero and the new bit becomes one. For example, the change from the largest three-bit value to the next value is:
This is the binary equivalent of carrying into a new place when counting in decimal.
Four-bit example
Four bits have 16 possible patterns, representing 0 through 15. The sequence begins as follows:
0000 represents 0.
0001 represents 1.
0010 represents 2.
0011 represents 3.
0100 represents 4.
It continues through 1111, which represents 15. Once all four bits are 1, every pattern available with four bits has been used. A fifth bit is needed to represent the next value, 16.
Place value in binary
Each position in a binary number has a place value that is a power of 2. Counting from the right, the positions have values 1, 2, 4, 8, and so on. A bit that is 1 contributes its place value; a bit that is 0 contributes nothing.
For example, in 10112, the 1s occupy the 8, 2, and 1 positions, so the value is:
The subscript 2 identifies a binary number, while the subscript 10 identifies a decimal number. This place-value system explains why each new position allows larger values to be represented.
Machine code and compilers
Computers ultimately operate on low-level instructions encoded in patterns of bits. Machine code is the form of instructions that a particular computer processor can execute. It is represented using binary values, although programmers generally do not write machine code directly.
A compiler is software that translates code written in a programming language into machine code that a computer can execute. This allows programmers to express instructions in a language designed for people, while the compiler handles the translation into a form usable by the machine.
The computer’s underlying electronic circuits use signal states, represented as bits, to store and process information; combinations of bits can encode numbers, instructions, and other forms of data.

Ask anything
We've read this whole study set, so questions about it get the best answers.