A1.2.2 - How Data is Stored in Binary

← Back to A1.2 overview

Data Units

UnitBytesBits
1 bit1
1 nibble½4
1 byte18
1 KB (kilobyte)1,0248,192
1 MB (megabyte)1,024²1,024² × 8
1 GB (gigabyte)1,024³1,024³ × 8
1 TB (terabyte)1,024⁴1,024⁴ × 8

Integers

Integers are stored as fixed-width binary numbers — every value uses the same number of bits regardless of its size, ensuring consistent memory use.

  • Unsigned integers: Use all bits for magnitude. Maximum value = 2n−1 where n = number of bits. Only represent non-negative values. Example: 4-bit max = 1111 = 15.
  • Two's complement (signed integers): The most significant bit (MSB) is the sign bit — 0 = positive, 1 = negative. A 4-bit two's complement can represent −8 to +7. To get a negative number: flip all bits of the positive value, then add 1.

Strings and Characters

  • ASCII: 7-bit code. Represents 128 unique characters.
    English letters, digits, punctuation. Example: 'A' = 1000001.
  • Unicode / UTF-8: Represents characters from all writing systems worldwide, not just English.
    • Variable-width: uses 1 to 4 bytes per character depending on the character.
    • Backward compatible with ASCII becpoupe the first 128 characters are identical.
    • 'A' = 01000001 in UTF-8 (same as ASCII).
    • Japanese, Arabic, emoji and other non-Latin characters require more than 1 byte.

Images

Audio

Analogue sound waves must be converted to digital binary form through two steps:

  • Sampling: Measuring the amplitude (volume) of the wave at regular intervals. The number of measurements per second = sampling rate, measured in Hz. Higher rate = more detail = more data.
  • Quantization: Mapping each sample to the nearest value in a fixed set. The number of possible values = bit depth.
  • Each sample is then encoded as a binary number. Stereo audio stores two channels (left + right), doubling data size.

Video

  • Video is a sequence of still images (frames) played at a rate that creates the illusion of motion.
  • Audio and video data are multiplexed (interleaved) to keep them synchronised during playback.
  • Video formats such as H.264 (AVC) and H.265 (HEVC) compress and encode the binary data for efficient storage and transmission.