Storing Data with Binary
How Binary is Used to Store Data
Binary digits are the basic units of computers, representing all types of data using just two symbols: 0 and 1. Every file, whether it is text, image, sound, or video, is ultimately stored and processed as a series of binary digits (bits). Understanding how data is encoded in binary is essential for grasping how computers store, retrieve, and manipulate information.
Binary Encoding Fundamentals
- Bit: The smallest unit of data in computing; can hold a value of 0 or 1.
- Byte: A group of 8 bits; can represent 256 different values (28).
- Data Representation: All data types are converted into binary before being stored in memory.
- Retrieval: Data is read from memory and decoded back into human-readable formats using the same encoding scheme.
Data Unit Sizes (decimal vs binary)
Computing uses two naming systems: decimal (SI) - kilo, mega, giga (10-based), common for drives and networks; and binary (IEC) - kibi, mebi, gibi (2-based), common for memory and operating systems. Know both.
Essential units
| Term | Size | Use Case(s) |
|---|---|---|
| Bit (b) | 1 bit | Binary state (0/1); flags; link speeds (Mb/s) |
| Nibble | 4 bits | One hex digit (0–F) |
| Byte (B) | 8 bits | Characters; file sizes; ASCII/UTF-8 units |
Decimal (SI units)
| Term | Size | Use Case(s) |
|---|---|---|
| Kilobyte (kB) | 10^3 = 1,000 bytes | Docs, small images; vendor disk/network specs |
| Megabyte (MB) | 10^6 = 1,000,000 bytes | Photos, app downloads, file sizes (marketing) |
| Gigabyte (GB) | 10^9 = 1,000,000,000 bytes | SSD/HDD capacity labels; mobile data plans |
| Terabyte (TB) | 10^12 = 1,000,000,000,000 bytes | Large drives, backups, video libraries |
Binary (IEC units)
| Term | Size | Use Case(s) |
|---|---|---|
| Kibibyte (KiB) | 2^10 = 1,024 bytes | Memory pages/blocks; OS/file-system units |
| Mebibyte (MiB) | 2^20 = 1,048,576 bytes | RAM/cache readouts; configuration limits |
| Gibibyte (GiB) | 2^30 = 1,073,741,824 bytes | OS-reported RAM/disk space |
| Tebibyte (TiB) | 2^40 = 1,099,511,627,776 bytes | NAS volumes; server storage (OS view) |
Reminder: bits (b) vs bytes (B) - 8 bits = 1 byte. Networks often use Mb/s; files and memory use MB/MiB.
Storing Different Types of Data
Each type of data is represented in binary using a specific format or standard.
Integers
Integers are stored using binary number systems. For example, the number 13 is stored as 00001101 in 8-bit binary.
- Unsigned binary: All bits represent magnitude only. All unsigned binary values are positive.
- Two's Complement: Signed binary. Allows both positive and negative numbers.
- Sign & Magnitude: Allows both positive and negative numbers, using the Most Significant Bit (MSB) to define positive or negative value.
Characters and Strings
Characters are stored using encoding systems like ASCII and Unicode. Each character corresponds to a unique binary code.
- ASCII: Uses 7 or 8 bits to store characters (e.g.
A=01000001). - Unicode: Supports thousands of characters using formats like UTF-8 and UTF-16.
- Strings: Stored as a sequence of character codes.
Images
Images are stored as binary data describing color values for each pixel. Two primary image types-bitmap and vector-use different approaches to represent visual content.
- Bitmap images Stores images as a grid of pixels, where each pixel has a defined color value stored in binary. File size depends on resolution and color depth.
- Vector images Stores images as mathematical formulas defining shapes, lines, and colors. Scales without loss of quality.
- Bitmap images are better for photographic detail.
- Vector images are ideal for clean, scalable graphics.
Calculating File Size
To calculate the file size of a bitmapped image file, we need to know:
- width (in pixels)
- height (in pixels)
- colour depth (in bits)
Audio
Audio is stored as binary values representing sound wave samples over time.
- Sample rate: Number of samples per second (e.g. 44.1 kHz).
- Bit depth: Number of bits used to represent each sample (e.g. 16-bit).
- Formats: WAV (uncompressed), MP3 (compressed), etc.
Calculating File Size
To calculate the file size of an audio file, we need to know:
- sample depth (in bits)
- sample rate (in Hertz)
- duration (in seconds)
- number of channels (e.g. mono, stereo)
Video
Video files are stored as a sequence of binary-encoded images (frames) with synchronized audio.
- Each frame is stored similarly to an image in binary form.
- Audio is interleaved with video and synchronized during playback.
- Common formats: MP4, AVI, MOV (all use binary storage with compression).
Metadata
Metadata refers to data that describes other data. In binary files, metadata provides critical context that helps software interpret how the content should be processed or displayed.
- Images: Metadata includes dimensions (width, height), color depth, compression type.
- Audio: Metadata might include duration, bitrate, codec used.
- Video: Metadata can define resolution, frame rate, aspect ratio, and codec information.
- Documents: Metadata may record creation date, author, language, and editing history.
Metadata is stored in binary alongside the content and enables accurate decoding, searching, categorization, and rendering of multimedia and textual data.
It also explains why the actual file size is often bigger than the calculated file size.
Key Takeaways
- All data in a computer is stored using binary digits (0s and 1s).
- Binary encoding determines how data is represented and interpreted.
- Different data types (e.g. integers, text, images, audio) use different encoding standards.
- Metadata plays a crucial role in describing the structure and context of binary data for correct interpretation.