Roadmap › How Computers Work — CPU, Memory, OS, Processes and Threads › Module: Data and the CPU
Lessons in this course (11)
1. Bits, bytes, number systems and encoding
Basic★ Must knowLesson 1 of 11
Computers store everything as bits (0/1). 8 bits = 1 byte.
| Unit | Size |
|---|---|
| Byte | 8 bits |
| KB / KiB | 1,000 / 1,024 bytes |
| MB, GB, TB | ×1,000 (or ×1,024 for MiB, GiB, TiB) |
Number systems: decimal (base 10), binary (base 2: 1011 = 11), hexadecimal (base 16: 0xFF = 255; two hex digits = one byte).
How data is represented:
| Data | Representation |
|---|---|
| Integers | Binary, two's complement for negatives (int = 32 bits: −2,147,483,648 … 2,147,483,647) |
| Decimals | IEEE 754 floating point (double = 64 bits: sign, exponent, mantissa) — why 0.1 isn't exact |
| Text | Characters → numbers via encodings: ASCII (7-bit), UTF-8 (1–4 bytes, the web standard), UTF-16 (.NET string/char, Windows) |
| Images, audio | Pixels/samples as numbers, usually compressed (JPEG, PNG, MP3) |
csharp
Console.WriteLine(Convert.ToString(11, 2)); // 1011
Console.WriteLine(0xFF); // 255
byte[] utf8 = Encoding.UTF8.GetBytes("₹100"); // ₹ takes 3 bytes in UTF-8
Console.WriteLine(utf8.Length); // 6
Console.WriteLine("₹100".Length); // 4 UTF-16 charsEndianness: order of bytes in multi-byte numbers — little-endian (x86, ARM usually) stores the least significant byte first; network protocols use big-endian ("network byte order").