ZIMSEC O-Level Computer Science (4021)
Data Representation: notes
AI-written, not yet teacher-reviewed
Not affiliated with or endorsed by ZIMSEC
Why binary
Computers store everything as bits (binary digits): 0 or 1, off or on. Numbers, text, pictures and sound are all turned into patterns of bits.
Place values
An 8-bit number has place values 128, 64, 32, 16, 8, 4, 2, 1.
- Binary to denary: add the place values that have a 1. Example: 00101101 = 32 + 8 + 4 + 1 = 45.
- Denary to binary: subtract the biggest place value that fits, write 1, carry on. Example: 13 = 8 + 4 + 1 = 00001101.
- Hexadecimal (base 16) uses 0 to 9 then A to F (A = 10, F = 15). One hex digit stands for 4 bits. Example: 1111 0010 = F2.
- Octal is base 8, using digits 0 to 7.
Binary addition
Rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0 carry 1, 1 + 1 + 1 = 1 carry 1. If the answer needs a ninth bit in an 8-bit register, that is an overflow.
Binary subtraction
Rules: 0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0, and 0 - 1 = 1 after borrowing 1 from the next column.
Units of storage
- 1 nibble = 4 bits; 1 byte = 8 bits
- 1 kilobyte (KB) = 1024 bytes; 1 megabyte (MB) = 1024 KB; 1 gigabyte (GB) = 1024 MB; 1 terabyte (TB) = 1024 GB
Logic gates
- AND: output 1 only when both inputs are 1.
- OR: output 1 when at least one input is 1.
- NOT: one input; the output is the opposite.
- NAND is AND then NOT; NOR is OR then NOT.
- A truth table lists every input combination. Two inputs give 4 rows; three inputs give 8 rows.
Gotcha: count place values from the right, starting at 1. The leftmost bit of 8 bits is worth 128, not 256.
Built by Allan Simoyi · X · GitHub · How it's built