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.

### 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
How many different values can four bits represent?

## Physical storage

Computers typically store bits using electromechanical transistors which can map electrical signals to either an on or off state. Learn more in our article From electricity to bits or this video on how transistors work.

## Want to join the conversation?

• How does the computer know whether a binary pattern results in the display of a letter or number?
• You (or the compiler you use) have to explicitly tell the computer how to interpret a bit string.

So when you write code you'd have to specify "This is a character" or "This is a binary number", high level programming language have functions to make that easier.
• Why did they come to learn 1s and 0s? Couldn't they learn our language?
• It's a computer lil bro
• I didn't understand how 4 bits can represent 16 values.Could you please explain.Thanks
• If we have 4 bits and each can be one of two values, then the number of combinations one can make with 4 bits is equal to 2*2*2*2 = 2^4 = 16.
• How does a computer know how to display this information?
• The computer know to display the info because it reads digital info in bits, and then outputs and converts those bits into visible things, like letters.
• "At , what are electromechanical transistors?"
• it focuses on the interaction of electrical and mechanical systems as a whole and how the two systems interact with eachother.
• why is this topic so complicated and stressful given the fact that i literally just found out about it today?
• becus copeters are coplcated.
• How would a computer know if 1000011 in a text file represents the number 67 or the letter C?
• It nows has a system in it and it travels as a bit it is converted into it when a computer reads it in 1's and 0's and is converted back into the digital form
hope it helps🙂
• I dont seem to understand a sequence of bits can anyone explain
• When you have more than one bit (or wire), the number of possible values increases. In 1 bit there are two possible values: 1 or 0. In 2 bits, there are four possible values, or combinations: 00, 01, 10, 11. With each additional bit, the number of possible values/combinations goes up by a factor of two.