Sign in

Intro to Computer Science

Unit 2

Binary and Data Representation

5 topics · 21 practice questions · Free responseNot yet reviewed

Notes

Binary and hexadecimal

  • Binary is base 2. Place values are 1, 2, 4, 8, 16, 32, 64, 128. Add the place values that have a 1 to convert to decimal.
  • With n bits there are 2 to the power n values. 8 bits give 256 values (0 to 255).
  • Hexadecimal is base 16 (0-9, A-F). One hex digit equals 4 bits. Binary addition: 1+1=10.

Text, images and sound

  • ASCII maps characters to numbers ('A' = 65, 'a' = 97). Unicode covers many languages and emoji.
  • An image is a grid of pixels; 24-bit RGB color uses 3 bytes per pixel. Sound is sampled many times per second.
  • File size grows with resolution, bits per pixel, sample rate and length.

Compression

  • Lossless compression is fully reversible (ZIP, PNG). Lossy removes some data for smaller files (JPEG, MP3).
  • Run-length encoding stores counts for repeats: "AAAB" becomes "3A1B".

Topics in this unit

Each topic has its own short notes and practice.

Practice

What is binary 1010 in decimal?
How many different values can 4 bits represent?
What is the binary value of the hex digit C?
The ASCII code for 'a' is 97. What is the ASCII code for 'c'?
A photo is 100 pixels wide and 50 pixels tall, using 3 bytes per pixel. How many bytes is it?
A music app uses a format that makes songs much smaller by permanently removing sounds most people cannot hear. This is:

Free response

Write your answer first, then open the scoring guide.

Free-response question

A game designer stores data for a small game.

(a) Convert the binary number 100101 to decimal. Show the place values you used.

Show the answer and scoring guide

32 + 4 + 1 = 37.

Check off the points you earned:

(b) A black-and-white sprite is 8 pixels wide and 8 pixels tall with 1 bit per pixel. How many bits and how many bytes does it need?

Show the answer and scoring guide

8 x 8 = 64 pixels, so 64 bits. 64 divided by 8 = 8 bytes.

Check off the points you earned:

(c) The designer compresses the game's text with run-length encoding. Encode "AAAAABBC" and say whether this compression is lossless or lossy.

Show the answer and scoring guide

The encoding is "5A2B1C". Run-length encoding is lossless because the original can be rebuilt exactly.

Check off the points you earned: