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.
- Predict the decimal value of 1101 and of 001011 before using the tool.
- The codes 2 2 1 use the dictionary 1 = "go", 2 = "team ". Predict the decoded text.
- 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
Starter
place value: 8 4 2 1bits: 1 1 0 1dictionary: 1 = "go", 2 = "team "payload codes: 2 2 1Worked case
| place value | 8 | 4 | 2 | 1 |
|---|---|---|---|---|
| bit | 1 | 1 | 0 | 1 |
| contributes | 8 | 4 | 0 | 1 |
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
- Use the bit cards to convert 1101 and 001011 to decimal, then check with the tool.
- Convert 13 and 16 to binary. Note how many bits 16 needs and connect this to L07 overflow.
- Decode 2 2 1, then try a code that is not in the dictionary and record what the tool reports.
- Enter 20, 12 and 10 in the size check and record the total and the saving.
- Change one size so the encoded version becomes smaller, and explain what made the difference.
Tests
| Input | Expected | Why this test |
|---|---|---|
| Binary 1101 to decimal | 13 | 8 + 4 + 1. |
| Binary 001011 to decimal | 11 | Leading zeros add nothing: 8 + 2 + 1. |
| Decimal 16 to binary | 10000 (5 bits) | 16 does not fit in 4 bits; the largest 4-bit value is 15. |
| Decode 2 2 1 | team team go | Each code is replaced exactly, so the encoding is lossless. |
| Decode 2 3 | Unknown code 3; no text | Without a dictionary entry the message cannot be reconstructed. |
| Original 20, payload 12, dictionary 10 | Total 22; not smaller (saves −2) | The dictionary is part of the cost. |
Explain and reflect
Explain
- Explain, using place values, why 001011 and 1011 represent the same number.
- Explain why the 12-byte payload alone is not a fair comparison with the 20-byte original.
- Explain one situation where lossy compression is acceptable and one where only lossless will do.
Reflect
- When would a dictionary-based encoding start saving space? What about the message would have to change?
- 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.