Free preview Digital information

Bits and bytes

Digital information comes in ones and zeroes.

๐Ÿ“„ How do computers represent data?

When we look at a computer, we see text and images and shapes.

To a computer, all of that is just **binary data**, 1s and 0s.

The following 1s and 0s represents a tiny GIF:

[[โ˜ƒ image 1]]

This next string of 1s and 0s represents a command to add a number:

[[โ˜ƒ image 2]]

You might be scratching your head at this point. Why do computers represent information in such a hard to read way? And how can 1s and 0s represent so many different things? That's what we'll explore in this lesson.

To start off, check out the next video from Code.org where engineers from Microsoft and Adafruit introduce the basics of bits and binary data.

๐Ÿ“„ Bits (binary digits)

Computers store information using bits. A bit (short for "binary digit") stores either the value $\texttt{0}$ or $\texttt{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?

State | Bit

  • | - | -
    [[โ˜ƒ image 2]] | $\texttt{0}$
    [[โ˜ƒ image 6]] | $\texttt{1}$

Is a button enabled or disabled?

State | Bit

  • | - | -
    [[โ˜ƒ image 12]] | $\texttt{0}$
    [[โ˜ƒ image 15]] | $\texttt{1}$

Is the current time AM or PM?

State | Bit

  • | - | -
    [[โ˜ƒ image 19]] | $\texttt{0}$
    [[โ˜ƒ image 21]] | $\texttt{1}$

[[โ˜ƒ graded-group 1]]

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:

$\texttt{0}\texttt{0}$, $\texttt{0}\texttt{1}$, $\texttt{10}$, $\texttt{11}$

A sequence of three bits can represent eight ($2^3$) different values:

$\texttt{0}\texttt{0}\texttt{0}$, $\texttt{0}\texttt{0}\texttt{1}$, $\texttt{0}\texttt{10}$, $\texttt{0}\texttt{11}$, $\texttt{10}\texttt{0}$, $\texttt{101}$, $\texttt{110}$, $\texttt{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 $\texttt{10}\texttt{0}\texttt{0}\texttt{0}\texttt{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

[[โ˜ƒ graded-group 1]]

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.

๐Ÿ“„ Bytes

A bit is the smallest piece of information in a computer, a single value storing either $\texttt{0}$ or $\texttt{1}$.

A byte is a unit of digital information that consists of $8$ of those bits.

Here's a single byte of information:

$\texttt{11110110}$

Here are three more bytes of information:

$\texttt{0}\texttt{0}\texttt{0}\texttt{0}\texttt{1010},\texttt{0}\texttt{101010}\texttt{0},\texttt{11011011}$

From bits to bytes

Conversion between bits and bytes is a simple calculation: divide by $8$ to convert from bits to bytes or multiply by $8$ to convert from bytes to bits. Try it yourself!

[[โ˜ƒ graded-group 1]]

[[โ˜ƒ graded-group 1]]

Why bytes?

What is so special about $8$ bits that it deserves its own name?

Computers do process all data as bits, but they prefer to process bits in byte-sized groupings. Or to put it another way: a byte is how much a computer likes to "bite" at once.

[[โ˜ƒ image 2]]

The byte is also the smallest addressable unit of memory in most modern computers. A computer with byte-addressable memory can not store an individual piece of data that is smaller than a byte.

[[โ˜ƒ image 4]]

What's in a byte?

A byte represents different types of information depending on the context. It might represent a number, a letter, or a program instruction. It might even represent part of an audio recording or a pixel in an image.

We'll explore how computers can use bits and bytes to represent all types of information in this unit.

Enjoying the free preview?

Lessons after number 3 are reserved for Pro members โ€” unlock the full course and every other one.

Sign up free Go Pro