Skip to main content

Pilot · Lab P05 · 45 minutes

Bits and compression choices

Convert between binary and decimal using place values, decode a short message with an explicit dictionary, and decide whether an encoded version is really smaller once the dictionary needed to reverse it is counted.

Predict first

Write your predictions before you use the tool.

  1. Predict the decimal value of 1101 and of 001011 before using the tool.
  2. The codes 2 2 1 use the dictionary 1 = "go", 2 = "team ". Predict the decoded text.
  3. A 20-byte original becomes a 12-byte payload that needs a 10-byte dictionary. Predict whether the encoded version is smaller.

Practice tool

The bits tool converts up to 8 bits to decimal and whole numbers up to 255 to binary, decodes codes with the fixed dictionary 1 = "go", 2 = "team ", and adds payload and dictionary sizes. It does not compress files, encrypt anything or judge which method is best.

Bits and dictionary · fixed rules

Binary to decimal

1 to 8 digits, each 0 or 1.

1×8 + 0×4 + 1×2 + 1×1 = 11

Decimal to 4 bits

0 to 15 fits in 4 bits; larger values show more bits.

11 = 1011

Decode with the dictionary 1="go", 2="team "

Codes separated by spaces, up to 20.

Decoded: "team team go"

Is the encoded version actually smaller?

12 + 10 = 22 bytes vs 20 original: 2 bytes larger

Starter

Bit cards (place values for 4 bits) · Data
place value:  8  4  2  1bits:         1  1  0  1
Dictionary and payload · Data
dictionary: 1 = "go", 2 = "team "payload codes: 2 2 1

Worked case

Worked conversion: 1101 in binary
place value8421
bit1101
contributes8401

8 + 4 + 0 + 1 = 13. Leading zeros add nothing: 001011 is 8 + 2 + 1 = 11. Going the other way, 13 needs the 8, then 4 (12), skip 2, then 1 (13): 1101.

Lossless decoding reverses the encoding exactly: replacing each code with its dictionary entry turns 2 2 1 back into "team team go". A code missing from the dictionary cannot be decoded and must be reported, not guessed.

Size has to count everything the receiver needs. Payload 12 bytes + dictionary 10 bytes = 22 bytes, which is 2 bytes more than the 20-byte original. For this short message the encoding does not save space. Lossy representations save space differently: they deliberately discard detail and cannot be reversed exactly.

Build

  1. Use the bit cards to convert 1101 and 001011 to decimal, then check with the tool.
  2. Convert 13 and 16 to binary. Note how many bits 16 needs and connect this to L07 overflow.
  3. Decode 2 2 1, then try a code that is not in the dictionary and record what the tool reports.
  4. Enter 20, 12 and 10 in the size check and record the total and the saving.
  5. Change one size so the encoded version becomes smaller, and explain what made the difference.

Tests

Tests for this lab
InputExpectedWhy this test
Binary 1101 to decimal138 + 4 + 1.
Binary 001011 to decimal11Leading zeros add nothing: 8 + 2 + 1.
Decimal 16 to binary10000 (5 bits)16 does not fit in 4 bits; the largest 4-bit value is 15.
Decode 2 2 1team team goEach code is replaced exactly, so the encoding is lossless.
Decode 2 3Unknown code 3; no textWithout a dictionary entry the message cannot be reconstructed.
Original 20, payload 12, dictionary 10Total 22; not smaller (saves −2)The dictionary is part of the cost.

Explain and reflect

Explain

  1. Explain, using place values, why 001011 and 1011 represent the same number.
  2. Explain why the 12-byte payload alone is not a fair comparison with the 20-byte original.
  3. Explain one situation where lossy compression is acceptable and one where only lossless will do.

Reflect

  1. When would a dictionary-based encoding start saving space? What about the message would have to change?
  2. Why is encoding with a dictionary not the same as encryption?

What this lab does not do

  • The tool converts at most 8 bits (up to 255) and decodes with one fixed dictionary.
  • The size check adds numbers you type; it does not measure or compress real files.
  • Nothing here encrypts or hides data, and nothing is saved.