1. Home
  2. Explore
  3. Computer Science
  4. Computer Science and Problem Solving

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

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 111 and 000:

  • 111 represents ON.

  • 000 represents OFF.

A bit (short for binary digit) is one unit of information that can represent either 000 or 111. At this introductory level, a bit can be thought of as recording the state of one transistor.

A bit has two possible values: 000 or 111. 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: 222 combinations: 000, 111.

  • Two bits: 444 combinations: 000000, 010101, 101010, 111111.

  • Three bits: 888 combinations.

  • Four bits: 161616 combinations.

For nnn bits, the total number of possible combinations is:

2n2^n2n

This occurs because each bit has 222 choices, and the choices are independent. For example, three bits have 2×2×2=23=82 \times 2 \times 2 = 2^3 = 82×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, nnn bits represent the values from 000 through 2n−12^n - 12n−1. Thus, the largest value is:

2n−12^n - 12n−1

For example:

  • Three bits provide 23=82^3 = 823=8 combinations, representing 000 through 777.

  • Four bits provide 24=162^4 = 1624=16 combinations, representing 000 through 151515.


Binary numbers and counting

A binary number is a number written using only the two digits 000 and 111. The word binary means “two-based.” The sequence below shows how three bits represent the values from 000 through 777:

  • 000000000 represents 000.

  • 001001001 represents 111.

  • 010010010 represents 222.

  • 011011011 represents 333.

  • 100100100 represents 444.

  • 101101101 represents 555.

  • 110110110 represents 666.

  • 111111111 represents 777.

The same counting pattern extends to any number of bits. In the bulb analogy, an ON bulb represents 111 and an OFF bulb represents 000. 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:

  1. Begin at the rightmost bit, which changes most often.

  2. If that bit is 000, change it to 111.

  3. If it is already 111, change it to 000 and carry the change one place to the left.

  4. Continue carrying left through any consecutive 111s. The first 000 encountered becomes 111.

  5. If every bit is already 111, all existing bits reset to 000 and an additional bit is needed to represent the next value.

For example, the three-bit pattern 011011011 represents 333. Adding one changes the rightmost 111 to 000, then carries left: the next 111 also becomes 000, and the leftmost 000 becomes 111. The result is 100100100, which represents 444.

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:

1112→10002111_2 \rightarrow 1000_21112​→10002​

This is the binary equivalent of carrying into a new place when counting in decimal.

Four-bit example

Four bits have 161616 possible patterns, representing 000 through 151515. The sequence begins as follows:

  • 000000000000 represents 000.

  • 000100010001 represents 111.

  • 001000100010 represents 222.

  • 001100110011 represents 333.

  • 010001000100 represents 444.

It continues through 111111111111, which represents 151515. Once all four bits are 111, every pattern available with four bits has been used. A fifth bit is needed to represent the next value, 161616.

Place value in binary

Each position in a binary number has a place value that is a power of 222. Counting from the right, the positions have values 111, 222, 444, 888, and so on. A bit that is 111 contributes its place value; a bit that is 000 contributes nothing.

For example, in 101121011_210112​, the 111s occupy the 888, 222, and 111 positions, so the value is:

10112=8+2+1=11101011_2 = 8 + 2 + 1 = 11_{10}10112​=8+2+1=1110​

The subscript 222 identifies a binary number, while the subscript 101010 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.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent