Unit 1 — Data¶
Exercise binary-annex.pdf · PDF
What you will learn
- How to read and write binary numbers — the one skill this unit is built on
- Why a "300 Mbps" line is not 300 MB/s (the ÷8 trap)
Computers are silly¶
Computers don't understand our languages or concepts — not words, not pictures, not "cat". They only understand:
- Electricity → 1
- No electricity → 0
Why only two states? Because they are impossible to confuse: a transistor is either conducting or not. Add noise, heat, interference... the gap between "some voltage" and "no voltage" is still huge. Binary = cheap and reliable. And two simple states are enough to build everything else, one yes/no question at a time.
Key idea
A bit can be 1 or 0
From bit to byte¶
A single bit is almost useless on its own, so computers group bits — and the ladder begins:
- 1 bit → yes / no, true / false, a coin flip
- 8 bits = 1 byte → 2⁸ = 256 possible values — enough for one character
For example, the letter H in ASCII:
A few ASCII anchors worth remembering
| Char | Decimal | Binary |
|---|---|---|
0 |
48 | 0011 0000 |
A |
65 | 0100 0001 |
a |
97 | 0110 0001 |
| space | 32 | 0010 0000 |
Fun fact: uppercase and lowercase differ by exactly one bit (65 vs 97 — flip the 32-bit and you toggle the case). Old programmers switched case by flipping a single bit.
Bytes keep stacking up: KB → MB → GB → TB.
Sizes you can feel
| Thing | Approximate size |
|---|---|
| One character of text | 1 byte |
| A short email | ~2 KB |
| A phone photo | ~3 MB |
| An MP3 song | ~5 MB |
| An HD movie | ~4 GB |
Where does the 0 come from?
Electricity means 1, no electricity means 0. Nothing physical, just our convention: any two clearly distinguishable states would do.
Counting in binary¶
You already know how to read numbers in base 10 — you learned it in primary school and then stopped noticing. Take 372:
Each position is worth 10 × the one to its right, because we have ten symbols (0–9).
Binary is exactly the same trick with two symbols: each position is worth 2 × the one to its right — the powers of two: 1, 2, 4, 8, 16, 32, 64, 128...
Reading a byte, step by step¶
Take the byte for H from the previous section: 0100 1000. Write the worth of each position under its bit:
| Bit | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|
| Worth | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Add up the values under every 1: 64 + 8 = 72. And in ASCII, 72 is H. That byte is no longer magic — you can read it.
Now try it yourself. Click a bit to flip it and watch the value change. Can you build H (72)? Then press +1 a few times and watch the 1s carry to the left, just like 0999 → 1000. Keep going past 255: a byte has no ninth box, so it rolls back to 0, like a car's mileage counter.
The other direction: decimal → binary¶
Divide by 2, note the remainder, repeat until you reach 0 — then read the remainders bottom to top:
72 ÷ 2 = 36 remainder 0 ↑
36 ÷ 2 = 18 remainder 0 ↑
18 ÷ 2 = 9 remainder 0 ↑ read
9 ÷ 2 = 4 remainder 1 ↑ bottom
4 ÷ 2 = 2 remainder 0 ↑ to
2 ÷ 2 = 1 remainder 0 ↑ top
1 ÷ 2 = 0 remainder 1 ↑
Remainders bottom-up: 0100 1000 — the same 72 again, full circle.
Your turn (answers inside)
- Convert
1011 0011to decimal. - Convert 200 to binary.
Answers
- 128 + 32 + 16 + 2 + 1 = 179
- Subtract powers of two: 200 − 128 = 72, 72 − 64 = 8, 8 − 8 = 0 → positions 128, 64 and 8 are 1 → 1100 1000
Count on your fingers, literally
Each finger is a bit: folded = 0, raised = 1. One hand counts 0–31, two hands 0–1023 — more than a full byte.
Hexadecimal: shorthand for humans¶
Binary is for machines, but humans often need to read raw bits too: colors, MAC addresses, memory dumps, error codes... Copying 32 bits by eye is how typos happen.
Hexadecimal (base 16) is the fix: each hex digit packs exactly 4 bits, so one byte is always exactly two hex digits.
| Hex | Binary | Hex | Binary |
|---|---|---|---|
0 |
0000 | 8 |
1000 |
1 |
0001 | 9 |
1001 |
2 |
0010 | A |
1010 |
3 |
0011 | B |
1011 |
4 |
0100 | C |
1100 |
5 |
0101 | D |
1101 |
6 |
0110 | E |
1110 |
7 |
0111 | F |
1111 |
The translation is mechanical — split the byte in half and look up each half:
(0x48 is the usual way to write "hex 48": 4 × 16 + 8 = 72 — our friend H again.)
You have met hex more times than you think:
- Colors:
#FF6600— three bytes: RFF(255), G66(102), B00(0) → orange - MAC addresses:
A4:5E:60:D2:1B:03— six bytes - Memory addresses, checksums, UUIDs...
Why not just decimal?
Because 4 bits ↔ 1 hex digit is mechanical, while 72 → 0100 1000 is not. Hex keeps every bit visible to the human eye — that is why every network tool, debugger and color picker speaks hex.
Units of storage vs. transfer¶
Two different families of units exist — and mixing them up is the most common mistake in the whole subject:
- Storage (capacity) → measured in bytes
- Transfer (speed) → measured in bits per second
Storage (capacity) → bytes¶
For sizes: files, RAM, disk capacity...
| Unit | Symbol | Equals |
|---|---|---|
| kilobyte | kB | 10³ B |
| megabyte | MB | 10⁶ B |
| gigabyte | GB | 10⁹ B |
| terabyte | TB | 10¹² B |
Beware: a binary version exists too, and Windows mixes both — it shows MiB (2²⁰ B = 1 048 576 B) but labels it "MB". That is why a "500 GB" disk shows ~465 "GB" in Windows: nothing is missing, it is just measuring with the other ruler.
Transfer (speed) → bits per second¶
For speeds: your Internet connection, Ethernet, Wi-Fi...
| Unit | Symbol | Equals |
|---|---|---|
| kilobit/s | Kbps | 10³ b/s |
| megabit/s | Mbps | 10⁶ b/s |
| gigabit/s | Gbps | 10⁹ b/s |
The ÷8 trap¶
Mbps ≠ MB/s. There are 8 bits in a byte, and the case of the letter matters:
- lowercase b = bit →
Mbps - uppercase B = byte →
MB/s
Real life
Your connection is 300 Mbps. You download a 700 MB file. How long?
- Speed in bytes: 300 ÷ 8 = 37.5 MB/s
- Time: 700 ÷ 37.5 ≈ 19 s
Your ISP is not lying when it says "300 Mbps" — it just counts bits, while you think in bytes.
Key takeaways¶
- Computers speak binary because two states are impossible to confuse: cheap and reliable.
- 8 bits = 1 byte = 256 values = one ASCII character — and you can now read a byte in binary and hex.
- Capacity is measured in bytes, speed in bits per second: divide by 8 before comparing.
Quick check¶
Test yourself:
1. Why do computers use binary (2 states) instead of, say, 10?
- Two states are impossible to confuse, even with noise
- Binary numbers are shorter to write down
- The mathematicians who invented them preferred base 2
- Ten states would use more electricity per calculation
Two states (electricity vs. no electricity) cannot be confused, so the system stays reliable even with noise. Complex behaviour is built from many tiny yes/no decisions.
2. A 400 Mbps connection: what is the maximum download speed in MB/s?
- 50 MB/s
- 400 MB/s
- 3,200 MB/s
- 40 MB/s
400 ÷ 8 = 50 MB/s. Remember: capacity is measured in bytes, speed in bits per second — always divide by 8 before comparing.
3. What is 1011 0011 in decimal?
- 179
- 178
- 211
- 200
1011 0011 = 128 + 32 + 16 + 2 + 1 = 179. To convert the other way (e.g. 200 to binary), subtract powers of two: 200 − 128 − 64 − 8 = 0 → 1100 1000.
4. Why do programmers write bytes in hexadecimal (0x48) instead of binary or decimal?
- Each hex digit stands for exactly 4 bits
- Computers store numbers internally in hexadecimal
- Hexadecimal was invented before binary
- Hex numbers are always shorter than their decimal versions
Hex is a shorthand for bits: each hex digit = exactly 4 bits, so a byte is always 2 digits and the translation is mechanical (0100 1000 → 48). Decimal (72) hides the bit structure.
5. How many different values can one byte hold?
- 256
- 255
- 8
- 128
A byte has 8 bits and each one is 0 or 1, so the combinations are 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 2⁸ = 256. The biggest value is 255 (1111 1111) only because counting starts at 0 (0000 0000) — that is the trap in "255".
6. What is 13 in binary?
- 0000 1101
- 0000 1011
- 1101 0000
- 0000 1110
Divide by 2 and keep the remainders: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Read them bottom to top: 1101 → 0000 1101. Check it with the position values: 8 + 4 + 1 = 13. Reading top to bottom gives 1011, which is 11 — the classic slip.
7. A byte holds 1111 1111 (255) and you add 1. What does the byte hold now?
- 0000 0000
- 1 0000 0000
- 1111 1111
- 0000 0001
Adding 1 carries all the way to the left, like 0999 → 1000. But a byte has only 8 boxes: the carry falls off the end and the byte shows 0000 0000, like a car's mileage counter rolling over.
8. H is 0100 1000 (72). Using the uppercase ↔ lowercase trick, what is h?
- 0110 1000
- 0100 1001
- 1100 1000
- 0010 1000
Uppercase and lowercase differ by exactly one bit: the one worth 32, third from the left. Flip it from 0 to 1: 0100 1000 → 0110 1000 = 64 + 32 + 8 = 104, which is h in ASCII. Same trick as A (65) → a (97).