Bits and Bytes Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Bits and Bytes.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

A bit is a single binary digit (0 or 1), the smallest unit of digital data. A byte is a group of 8 bits that can represent 256 different values (0 to 255), enough to encode one text character. All digital storage and communication is measured in bits and bytes.

A bit is the smallest piece of data. A byte is enough to store one character.

Read the full concept explanation β†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: All digital dataβ€”text, images, musicβ€”is ultimately stored as sequences of bits grouped into bytes.

Common stuck point: KB, MB, GB are 1024Γ—1024\times each other, not 1000Γ—1000\times (though marketing often uses 1000).

Sense of Study hint: When converting between bits and bytes, remember that 1 byte = 8 bits. To find how many values nn bits can represent, compute 2n2^n. To convert storage units, use the chain: 1 KB = 1024 bytes, 1 MB = 1024 KB, 1 GB = 1024 MB.

Common Mistakes to Watch For

Before you work through the examples, skim the mistake guide so you know which shortcuts and sign errors to avoid.

Worked Examples

Example 1

easy
How many different values can be represented with 3 bits? List all possible 3-bit binary patterns.

Answer

8 different values (0 to 7): 000, 001, 010, 011, 100, 101, 110, 111.

First step

1
Step 1: Each bit can be 0 or 1. With 3 bits, the number of combinations is 23=82^3 = 8.

Full solution

  1. 2
    Step 2: The patterns are: 000, 001, 010, 011, 100, 101, 110, 111.
  2. 3
    Step 3: These represent the values 0 through 7 in decimal. In general, n bits can represent 2n2^n different values.
A bit is the smallest unit of data (0 or 1). The number of possible values doubles with each additional bit: 1 bit = 2 values, 2 bits = 4, 3 bits = 8, and so on.

Example 2

medium
Convert between storage units: (a) How many bytes in 2 kilobytes? (b) A file is 3,145,728 bytes β€” how many megabytes is that? (c) How many bits in 1 byte?

Example 3

medium
You need a unique code for each of 500 items. How many bits and how many whole bytes are required?

Example 4

hard
A 1024 by 768 image uses 24 bits per pixel. What is the uncompressed size in MiB (round to two decimals)?

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
An image is 800 Γ— 600 pixels. Each pixel uses 24 bits (8 bits each for red, green, blue). What is the uncompressed file size in megabytes?

Example 2

hard
A colour system uses 4 bits per colour channel (red, green, blue). (a) How many shades can each channel represent? (b) How many unique colours are possible in total? (c) Compare this to standard 8-bit-per-channel colour.

Example 3

easy
How many bits are in one byte?

Example 4

easy
How many different values can one byte (8 bits) represent?

Example 5

easy
What is the smallest unit of digital data?

Example 6

easy
How many values can 4 bits represent?

Example 7

easy
A file is `8 bits`. How many bytes is that?

Example 8

easy
Roughly how many bytes are in 1 kilobyte (binary, kibibyte)?

Example 9

easy
How many bits are needed to store one standard (extended) ASCII character?

Example 10

easy
In the abbreviation `MB` vs `Mb`, which means megabytes?

Example 11

medium
How many values can 10 bits represent?

Example 12

medium
A `100 Mb/s` connection. How many megabytes per second is that (approx)?

Example 13

medium
How many bits are needed to give every one of 30 students a unique ID number?

Example 14

medium
A 3-byte value spans how many bits?

Example 15

medium
Adding one bit to a value's width changes the number of representable values how?

Example 16

medium
A pixel uses 3 bytes (one per red, green, blue). How many distinct colors can it represent?

Example 17

medium
How many bytes are needed to store the text "HELLO" in ASCII (one byte per character)?

Example 18

challenge
A counter is 8 bits and currently holds 255. It is incremented by 1. What value does it hold (assuming unsigned wraparound)?

Example 19

challenge
To address every byte in 1 MiB (2^20 bytes) of memory uniquely, how many address bits are required?

Example 20

challenge
Storing 1000 records, each needing a unique numeric key. What is the minimum number of BYTES per key (whole bytes)?

Example 21

medium
How many bytes are in 2 kibibytes (KiB)?

Example 22

medium
A value needs 12 bits. How many whole bytes are required to store it?

Example 23

easy
How many bytes are in 16 bits?

Example 24

easy
How many different values can 2 bits represent?

Example 25

easy
How many values can 6 bits represent?

Example 26

easy
A file is 32 bits. How many bytes is that?

Example 27

easy
Roughly how many bytes in 1 mebibyte (MiB)?

Example 28

easy
How many bits are in 3 bytes?

Example 29

medium
How many values can 12 bits represent?

Example 30

medium
A `200 Mb/s` connection. How many megabytes per second is that (approx, using 8 bits per byte)?

Example 31

medium
How many bits are needed to give every one of 100 students a unique ID number?

Example 32

medium
A 4-byte value spans how many bits?

Example 33

medium
A pixel uses 2 bytes (16 bits) for color. How many distinct colors can it represent?

Example 34

medium
How many bytes are needed to store the text "COMPUTE" in ASCII (one byte per character)?

Example 35

medium
How many KiB are in 1 MiB?

Example 36

medium
How many bits are in 5 bytes?

Example 37

medium
How many bytes are in 4 KiB?

Example 38

medium
How many bits does a single ASCII character require?

Example 39

hard
A counter is 8 bits and currently holds 200. It is incremented by 100. What value does it hold (unsigned wraparound)?

Example 40

hard
To address every byte in 64 KiB (2162^{16} bytes) of memory uniquely, how many address bits are required?

Example 41

hard
You're storing 70,000 unique IDs. What is the minimum number of WHOLE BYTES per ID?

Example 42

hard
How many bytes are in 2 GiB?

Example 43

challenge
A song file is 4 MiB. At a download speed of 16 Mb/s (megabits per second), about how many seconds does it take to download?

Background Knowledge

These ideas may be useful before you work through the harder examples.

binary