4CP0 · Topic 2 of 12

Data Representation

How computers represent numbers, text, images, and sound using binary and hexadecimal systems.

~6Minutes
4Key points
30Questions
All Computer Science topics

Study path

Learn it, recall it, then prove it

01 · Understand

Read the explanation and work through each example.

02 · Recall

Close the notes and explain the main idea yourself.

03 · Practise

Attempt the quiz, then revisit only missed concepts.

Introduction to Data Representation

At the most fundamental level, a computer is an electronic device made of billions of tiny switches. Each switch can be in one of two states: on or off. We represent these two states using the digits 1 (on) and 0 (off). This two-digit number system is called binary (base-2), and it is the language of all digital computers. Every piece of information—from the text in this document to a high-definition video—is stored and processed as vast sequences of these 0s and 1s.

Units of Data Storage

The smallest unit of data is a bit (binary digit), which can be either a 0 or a 1. To represent more complex information, bits are grouped together.

  • Byte: A group of 8 bits. A byte is the standard unit for measuring file size and memory capacity.
  • Kilobyte (KB): 1,000 bytes. (Note: Historically, this was 1024 bytes, but the SI standard of 1000 is now common).
  • Megabyte (MB): 1,000 kilobytes (1 million bytes).
  • Gigabyte (GB): 1,000 megabytes (1 billion bytes).
  • Terabyte (TB): 1,000 gigabytes (1 trillion bytes).

Exam Trap: Be careful with units! Internet speeds are often measured in megabits per second (Mbps), while file sizes are in megabytes (MB). Since 1 byte = 8 bits, a 100 Mbps connection will download a 100 MB file in approximately 8 seconds, not 1 second.

Number Systems

Computers use binary, but humans find it easier to work with decimal (denary) and hexadecimal systems.

Binary (Base-2)

Uses only two digits: 0 and 1. Each position represents a power of 2, starting from the right (2⁰, 2¹, 2², etc.).

  • Example (Binary to Denary): Convert 11010110₂ to denary.
  • Place values: 128, 64, 32, 16, 8, 4, 2, 1
  • Binary string: 1 1 0 1 0 1 1 0
  • Calculation: (1×128) + (1×64) + (0×32) + (1×16) + (0×8) + (1×4) + (1×2) + (0×1) = 128 + 64 + 16 + 4 + 2 = 214₁₀

Denary (Decimal, Base-10)

The number system we use daily, with digits 0-9.

  • Example (Denary to Binary): Convert 45₁₀ to binary.
  • Use repeated division by 2 and record the remainders.
  • 45 ÷ 2 = 22 remainder 1
  • 22 ÷ 2 = 11 remainder 0
  • 11 ÷ 2 = 5 remainder 1
  • 5 ÷ 2 = 2 remainder 1
  • 2 ÷ 2 = 1 remainder 0
  • 1 ÷ 2 = 0 remainder 1
  • Read the remainders from bottom to top: 101101₂

Hexadecimal (Base-16)

Uses 16 symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Hexadecimal is used by programmers as a human-friendly shorthand for binary because it is very compact.

  • Why use Hex? One hexadecimal digit represents exactly four binary bits (a nibble). This makes conversion simple and reduces the long strings of 0s and 1s, making it easier to read memory addresses, MAC addresses, and define colours in web design (e.g., #FF0000 for red).
  • Conversion (Binary ↔ Hex):
  • Binary to Hex: Group binary digits into nibbles (4s) from right to left. Convert each nibble to its hex equivalent.
  • Example: 11101001₂1110 1001 → E 9 → E9₁₆
  • Hex to Binary: Convert each hex digit into its 4-bit binary equivalent.
  • Example: 3B₁₆3 B0011 101100111011₂

Representing Text: ASCII and Unicode

Computers store text by assigning a unique binary code to each character.

  • ASCII (American Standard Code for Information Interchange): An early 7-bit standard, representing 128 characters (letters, numbers, punctuation). For example, 'A' is 65 (01000001₂). Its main limitation is that it only covers English characters.
  • Unicode: A modern, universal standard that solves ASCII's problem. It uses 16 or 32 bits per character, providing codes for over 140,000 characters from virtually every language, including the Nastaliq script used for Urdu. This is why a modern smartphone or a website like Jang newspaper can correctly display and process text in both English and Urdu.

Representing Images: Pixels and Bitmaps

Bitmap images are stored as a grid of tiny dots called pixels (picture elements).

  • Resolution: The dimensions of the pixel grid, written as width × height (e.g., 1920 × 1080). Higher resolution means more pixels, resulting in a more detailed image but a larger file size.
  • Colour Depth (or Bit Depth): The number of bits used to store the colour of a single pixel. The number of possible colours is 2^(colour depth).
  • 1-bit: 2¹ = 2 colours (monochrome)
  • 8-bit: 2⁸ = 256 colours
  • 24-bit (True Colour): 2²⁴ ≈ 16.7 million colours
  • Image File Size Calculation:
  • File Size (in bits) = Resolution Width × Resolution Height × Colour Depth
  • Example: A 100x50 pixel image with 8-bit colour depth would be 100 × 50 × 8 = 40,000 bits. To get the size in bytes, divide by 8: 40,000 / 8 = 5,000 bytes or 5 KB.

Representing Sound: Sampling

Sound in the real world is a continuous analogue wave. To store it on a computer, it must be converted into a digital format through a process called sampling.

  • Sampling: The amplitude (height) of the sound wave is measured at regular time intervals. Each measurement is called a sample.
  • Sample Rate: The number of samples taken per second, measured in Hertz (Hz). A higher sample rate (e.g., 44,100 Hz for CD quality) captures the sound wave more accurately, leading to higher fidelity sound but a larger file size.
  • Bit Depth (for audio): The number of bits used to store the value of each sample's amplitude. A higher bit depth provides a greater dynamic range (the difference between the quietest and loudest sounds), improving quality and increasing file size.
  • Sound File Size Calculation:
  • File Size (in bits) = Sample Rate (Hz) × Bit Depth × Duration (seconds) × Number of Channels (e.g., 1 for mono, 2 for stereo)
  • Example: A 10-second stereo recording at 44.1 kHz with 16-bit depth would be: 44100 × 16 × 10 × 2 = 14,112,000 bits, or approximately 1.76 MB.

Quick revision infographic

Computer Science · Quick revision

Data Representation

Key concepts

  1. 01Binary: base 2, each bit doubles in value
  2. 02Hex: base 16, one digit = 4 bits
  3. 03Image size = pixels × colour depth ÷ 8 bytes
  4. 04Sound: sample rate × bit depth × duration = file size

Formulas to know

Hex: base 16, one digit = 4 bits
Image size = pixels × colour depth ÷ 8 bytes
Sound: sample rate × bit depth × duration = file size
NADRA's Database — Binary Data for 220 Million Pakistanis

Every CNIC in Pakistan is stored digitally by NADRA. Your name is stored in ASCII/Unicode, your photo in pixels (binary colour values), and your fingerprint as a compressed binary file. NADRA's B-grade ID card photo might be 200×200 pixels at 24-bit colour = 200×200×24 = 960,000 bits = 120,000 bytes = ~117 KB before compression. Real binary maths applied to national data.

SeekhoAsaan.com · Free revisionData Representation

Test your knowledge.

30 explained questions. Har answer ke baad reasoning foran milegi.

10 Beginner10 Intermediate10 Advanced
Start 30-question quiz