If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

## AP®︎/College Computer Science Principles

### Course: AP®︎/College Computer Science Principles>Unit 1

Lesson 1: Bits and bytes

# Bits (binary digits)

Computers store information using bits. A bit (short for "binary digit") stores either the value $\mathtt{\text{0}}$ or $\mathtt{\text{1}}$.

## What fits in a bit?

A single bit can only represent two different values. That's not very much, but that's still enough to represent any two-valued state.
Is a lightbulb on or off?
StateBit
$\mathtt{\text{0}}$
$\mathtt{\text{1}}$
Is a button enabled or disabled?
StateBit
$\mathtt{\text{0}}$
$\mathtt{\text{1}}$
Is the current time AM or PM?
StateBit
$\mathtt{\text{0}}$
$\mathtt{\text{1}}$
Consider this settings screen for a Khan Academy user:
Which of the settings can be stored in a single bit?

## Sequences of bits

Computers use multiple bits to represent data that is more complex than a simple on/off value.
A sequence of two bits can represent four (${2}^{2}$) distinct values:
$\mathtt{\text{0}}\mathtt{\text{0}}$, $\mathtt{\text{0}}\mathtt{\text{1}}$, $\mathtt{\text{10}}$, $\mathtt{\text{11}}$
A sequence of three bits can represent eight (${2}^{3}$) different values:
$\mathtt{\text{0}}\mathtt{\text{0}}\mathtt{\text{0}}$, $\mathtt{\text{0}}\mathtt{\text{0}}\mathtt{\text{1}}$, $\mathtt{\text{0}}\mathtt{\text{10}}$, $\mathtt{\text{0}}\mathtt{\text{11}}$, $\mathtt{\text{10}}\mathtt{\text{0}}$, $\mathtt{\text{101}}$, $\mathtt{\text{110}}$, $\mathtt{\text{111}}$
A sequence can represent many things: a number, a character, a pixel. Plus, the same sequence can represent different types of data in different contexts. The sequence $\mathtt{\text{10}}\mathtt{\text{0}}\mathtt{\text{0}}\mathtt{\text{0}}\mathtt{\text{11}}$ could represent $67$ in a calculator application while also representing the letter "C" in a text file. Learn more in our lessons on Binary numbers and Storing text in binary