notes
DATA REPRESENTATION
1. Binary Represents Data
● All data (text, images, numbers, sound) must be converted into binary for a computer to
process.
● Computers use millions of tiny switches (transistors) which can be:
○ ON = 1
○ OFF = 0
1.1 Number Systems
1.1.1 Binary, Denary & Hexadecimal
Denary (Base 10)
● Uses digits 0–9.
● Example - 25674
(104) 10000 (103) 1000 (102)100 (101)10 (100)1
2 5 6 7 4
Binary (Base 2)
● Uses digits 0 and 1 only.
● Place values: 128 64 32 16 8 4 2 1 (2⁷ to 2⁰ for 8-bit).
25 24 23 22 21 20
32 16 8 4 2 1
Converting Binary → Denary
Method: Add up the column values where binary = 1.
Example:
11101110
= 128 + 64 + 32 + 8 + 4 + 2
= 238
Steps:
1. Write place values.
2. Add only where there is a 1.
Converting Denary → Binary
Method 1: Successive Subtraction
● Subtract the biggest possible power of 2.
● Mark 1 where subtraction happens, 0 where it doesn’t.
Method 2: Division by 2 (Remainders Method)
● Keep dividing by 2.
● Write remainders.
● Read remainders bottom → top.
Hexadecimal System (Base 16)
Hex digits:
0–9 and A(10), B(11), C(12), D(13), E(14), F(15)
Place values:
4096, 256, 16, 1 (16³, 16², 16¹, 16⁰)
Binary ↔ Hex relationship
● 1 hex digit = 4 binary bits
● Example:
○ Hex A = Binary 1010
○ Hex F = Binary 1111
Converting Binary → Hex
1. Split binary into groups of 4 from the right.
2. Add leading zeros if needed.
3. Convert each group using the lookup table.
Example:
101111100001
→ 1011 1110 0001
→BE1
Converting Hex → Binary
● Replace each hex digit with its 4-bit binary equivalent.
Example:
4 5 A
→ 0100 0101 1010
Converting Hex → Denary
Multiply each digit by its place value.
Example:
45A
4 × 256 = 1024
5 × 16 = 80
A (10) × 1 = 10
Total = 1114
Converting Denary → Hex
Two methods:
1. Convert denary → binary → hex
2. Successively divide by 16 (similar to binary division).
1.1.3 Hexadecimal System and Addressing
As we have seen, a computer can only work with binary data. While computer scientists can
work with binary, they find hexadecimal more convenient. This is because one hex digit
represents four binary digits.
Example: 1101001010101111 in binary = D2AF in hexadecimal. Hex is easier for humans to
remember, copy, and work with.
Uses of the Hexadecimal System
1. Error Codes
Error codes are often shown as hexadecimal values. These numbers refer to memory
locations of errors and are usually automatically generated by the computer.
Programmers use hex to interpret these errors.
2. MAC Addresses (Media Access Control)
○ A MAC address uniquely identifies a device on a network.
○ Usually 48 bits (6 bytes), shown as 6 groups of two hexadecimal digits:
NN:NN:NN:DD:DD:DD or NN-NN-NN-DD-DD-DD
■ First half (NN-NN-NN) → manufacturer ID
■ Second half (DD-DD-DD) → device serial number
3. Example:
○ 00:1C:B3:4F:25:FE → Apple device (Manufacturer code 001CB3, Serial
4F25FE)
○ Other manufacturers:
■ Dell → 00:14:22
■ Cisco → 00:40:96
■ Intel → 00:A0:C9
4. IP Addresses (Internet Protocol)
○ IPv4: 32-bit number, written in decimal ([Link]) or hex
(77.76.9e.01)
○ IPv6: 128-bit number, written in hexadecimal, separated by colons:
Example: a8fb:7a88:fff0:0fff:3d21:2085:66fb:f0fa
5. Differences Between MAC and IP Addresses
Feature MAC Address IP Address
Type Hardware/phy Logical/network
sical
Format 48 bits, 32-bit IPv4 or 128-bit IPv6
hexadecimal
Permanence Permanent Can change (dynamic/static)
(assigned by
manufacturer)
[Link] Colour Codes
○ HTML uses hexadecimal to represent colours (RGB values).
○ Each colour component (Red, Green, Blue) ranges from 00 to FF (0–255
decimal).
○ Example codes:
■ #FF0000 → Red
■ #00FF00 → Green
■ #0000FF → Blue
■ #FF00FF → Fuchsia
■ #FF8000 → Orange
■ #B18904 → Tan
○ Total possible colours: 256 × 256 × 256 = 16,777,216
○ Format: #RRGGBB, where RR = red, GG = green, BB = blue.
Binary Addition, Overflow, Shifts & Two’s Complement
1. Binary Addition – Key Facts
Adding bits
1+0=1
1 + 1 = 0 (sum) 1 (carry)
1 + 1 + 1 = 1 (sum) 1 (carry)
Example 1
12 → 01111100
2 → 00011110
Add:
= 10111100
Denary = 12 + 2 = 14 (matches).
4. Logical Binary Shifts
Shift Left (×2)
● Each left shift = multiply by 2.
● Leftmost dropped → error possible.
● Empty right positions filled with 0.
Example:
00010101 (21)
Shift left 1 → 00101010 (42)
Shift left 2 → 01010100 (84)
Shift Right (÷2)
● Each right shift = divide by 2.
● Rightmost 1 lost → error possible.
● Empty left positions filled with 0.
Example:
11001000 (200)
Shift right 1 → 01100100 (100)
Too many shifts → incorrect because bits lost.
5. Two’s Complement (8-bit)
● Used for signed integers.
● Left-most bit represents sign:
○ 0 → positive
○ 1 → negative
● Range = −128 to +127
Positive numbers
Same as normal binary:
e.g.
+25 → 00011001
+125 → 01111101
6. Converting From Two’s Complement to Denary
Positive (left bit = 0)
→ Sum place values normally.
Example:
01101110
= 64 + 32 + 8 + 4 + 2 = 110
7. Writing Negative Numbers in Two’s Complement
Method:
1. Write positive binary.
2. Invert bits.
3. Add 1.
Example:
−13
13 = 00001101
Invert → 11110010
Add 1 → 11110011
8. Detecting Errors in Shifts
● Losing leftmost 1 (in left shift) → multiplication overflow.
● Losing rightmost 1 (in right shift) → division incorrect
1.2 Text, Sound & Images
1.2.1 Character Sets – ASCII & Unicode
ASCII
● Standard ASCII → 7 bits, 128 characters
● Codes 0–31 → control codes
● Uppercase & lowercase differ by 1 bit (6th bit)
● Characters are grouped sequentially → easy processing
● Extended ASCII → 8 bits, 256 characters
● Limitation: cannot represent symbols of many languages (Chinese, Sinhala, etc.)
Unicode
● Created to support all languages
● Uses 16-bit or 32-bit encoding
● First 128 characters overlap with ASCII
● Supports thousands of characters
● Solves ASCII incompatibility (DOS vs Windows differences)
1.2.2 Sound Representation
Sound is analogue
● Computers need digital → sound is sampled using an ADC
● Sampling stores approximate amplitude values at fixed time intervals
Key Terms
● Sampling rate → samples per second (Hz)
● Bit depth (sampling resolution) → bits per sample
● Higher sampling rate/bit depth → better quality but larger file size
Formula (Mono)
File size = sample rate × bit depth × time
For Stereo → multiply by 2
1.2.3 Bitmap Images
Pixels
● Images made of a matrix of pixels
● Pixel colour depends on colour depth
Colour depth
● Bits per pixel
● 1 bit → 2 colours
● 2 bits → 4 colours
● 3 bits → 8 colours
● 8 bits → 256 colours
● 24 bits → ~16 million colours (True Colour)
Resolution
● Number of pixels (e.g., 4096 × 3072)
● Higher resolution → sharper, but larger file size
File size (Image)
File size = resolution × colour depth
1.3 Data Storage & File Compression
1.3.1 Measuring Data Storage
Denary (SI) units
● 1 KB = 1000 bytes
● 1 MB = 1,000,000 bytes
● 1 GB = 1,000,000,000 bytes
● 1 TB = 1,000,000,000,000 bytes
Binary (IEC) units
● 1 KiB = 2¹⁰ = 1024 bytes
● 1 MiB = 2²⁰ bytes
● 1 GiB = 2³⁰ bytes
● 1 TiB = 2⁴⁰ bytes
Used for RAM/ROM.
1.3.2 File Size Calculations
Bitmap Image
File size = (height × width × colour depth)
Sound File
Mono:
File size = sample rate × bit depth × duration
Stereo:
Multiply by 2
1.3.3 File Compression
Why compress?
● Save storage
● Faster uploads/downloads
● Reduce bandwidth usage
● Cut costs (e.g., cloud storage)
Lossy Compression
● Removes data permanently
● Smaller files
● Slight quality loss
Examples:
● MP3 → removes inaudible frequencies
● MP4 → multimedia (video + audio)
● JPEG → image compression by reducing colour data/resolution
Lossless Compression
● No data lost
● Original file can be reconstructed
● Used for text, documents, PNG images
questions
1. Define a bit.
➤ A single binary digit (0 or 1).
2. What is a byte?
➤ 8 bits.
3. What is the purpose of binary in computers?
➤ To represent and process all data using 0s and 1s.
4. What does ASCII stand for?
➤ American Standard Code for Information Interchange.
5. Why is Unicode needed?
➤ To represent characters from all languages.
6. What is colour depth?
➤ Number of bits used per pixel.
7. What is sampling rate?
➤ Number of samples taken per second in sound recording.
8. What is a pixel?
➤ Smallest element of a digital image.
9. What is a bitmap image?
➤ Image made up of pixels.
10.What does lossless compression do?
➤ Reduces file size without losing data.
11.What does lossy compression remove?
➤ Unnecessary or less important data.
12.What is a logic gate?
➤ Basic building block of digital circuits that performs a logical operation.
13.What is a truth table?
➤ Table showing all possible inputs and outputs of a logic gate.
14.What is hexadecimal used for?
➤ Compact human-friendly representation of binary.
15.What is overflow?
➤ When a calculation produces a value too large for the available bits.
1) Binary 1101₂ equals:
➤ 13
2) Hexadecimal A5₁₆ equals (in denary):
➤ 165
3) 1 nibble =
➤ 4 bits
4) Which is a lossless compression method?
➤ Run-length encoding (RLE)
5) Which logic gate outputs 1 only if both inputs are 1?
➤ AND
6) Which gate outputs 1 when inputs are different?
➤ XOR
7) ASCII uses how many bits?
➤ 7 bits
8) Unicode UTF-16 uses how many bits per character?
➤ 16 bits
9) Colour depth of 24-bit supports how many colours?
➤ 16.7 million
10) The smallest unit of digital sound is a:
➤ Sample
11) Increasing sampling rate increases:
➤ Sound quality
12) Pixel density is measured in:
➤ PPI
13) Which number system is base 16?
➤ Hexadecimal
14) Binary 10000000₂ (8-bit two’s complement) represents:
➤ –128
15) A MAC address is usually written in:
➤ Hexadecimal
16) Which file type is typically uncompressed?
➤ BMP
17) JPEG uses which compression?
➤ Lossy
18) Which term means number of bits per second in audio?
➤ Bit rate
19) 1 kilobyte (decimal) =
➤ 1000 bytes
20) 1 kilobyte (binary KiB) =
➤ 1024 bytes
1) Denary → Binary (Division by 2 method)
Q: Convert 174₁₀ to binary.
Steps / Answer
1. Divide by 2, record remainder each step:
○ 174 ÷ 2 = 87 remainder 0
○ 87 ÷ 2 = 43 remainder 1
○ 43 ÷ 2 = 21 remainder 1
○ 21 ÷ 2 = 10 remainder 1
○ 10 ÷ 2 = 5 remainder 0
○ 5 ÷ 2 = 2 remainder 1
○ 2 ÷ 2 = 1 remainder 0
○ 1 ÷ 2 = 0 remainder 1
2. Read remainders bottom → top: 10101110₂.
Final: 174₁₀ = 10101110₂
2) Binary → Denary
Q: Convert 1101011₂ to denary.
Steps / Answer
1. Write place values (right to left): 1, 2, 4, 8, 16, 32, 64.
2. Multiply and add where bit = 1:
○ bits: 1 1 0 1 0 1 1 → 64 + 32 + 0 + 8 + 0 + 2 + 1 = 107.
Final: 1101011₂ = 107₁₀
3) Hexadecimal → Denary
Q: Convert 3A9₁₆ to denary.
Steps / Answer
1. Place values for hex (from right): 16²=256, 16¹=16, 16⁰=1.
2. Convert digits: 3, A = 10, 9.
3. Compute: 3×256 + 10×16 + 9×1 = 768 + 160 + 9 = 937.
Final: 3A9₁₆ = 937₁₀
4) Binary → Hexadecimal
Q: Convert 101111100001₂ to hex.
Steps / Answer
1. Group bits into groups of 4 from the right: 1011 1110 0001.
2. Convert each nibble:
○ 1011 = B
○ 1110 = E
○ 0001 = 1
3. Combine: BE1₁₆.
Final: 101111100001₂ = BE1₁₆
5) Binary Addition (with carries)
Q: Add 01011011₂ and 00110101₂. Show carries.
Steps / Answer
1. Write vertically and add from rightmost bit:
0 1 0 1 1 0 1 1 (91)
+ 0 0 1 1 0 1 0 1 (53)
-------------------
2. Rightmost column:
○ 1 + 1 = 0 (sum) carry 1
○ next: 1 + 0 + carry1 = 0 carry1
○ next: 0 + 1 + carry1 = 0 carry1
○ next: 1 + 0 + carry1 = 0 carry1
○ next: 1 + 1 + carry1 = 1 carry1 (since 1+1+1 = sum 1 carry 1)
○ next: 0 + 1 + carry1 = 0 carry1
○ next: 1 + 0 + carry1 = 0 carry1
○ leftmost: 0 + 0 + carry1 = 1 carry0
3. Result bits (left→right): 1 0 0 1 0 0 0 0 → 10010000₂
4. Check in denary: 91 + 53 = 144. 10010000₂ = 128 + 16 = 144 ✅
Final: 01011011₂ + 00110101₂ = 10010000₂ (144₁₀)
6) Logical Shift Left / Right
Q: Shift 00010101₂ (21) left by 2 places. What decimal value results? Any error possible?
Steps / Answer
1. Original: 00010101
2. Shift left by 1 → 00101010 (multiply by 2 → 42)
3. Shift left by 2 → 01010100 (multiply by 2 again → 84)
4. Decimal: 84.
Note: If significant bits are dropped (leftmost 1 falls off) overflow occurs — here no
overflow in 8-bit representation.
Final: After left shift by 2: 01010100₂ = 84₁₀
7) Two’s Complement — Writing Negative Number
Q: Write −18 in 8-bit two’s complement.
Steps / Answer
1. Write +18 in 8-bit binary: 18 = 00010010.
2. Invert bits: 11101101.
3. Add 1: 11101101 + 1 = 11101110.
Final: −18 = 11101110₂ (8-bit two’s complement)
8) Two’s Complement — Convert to Denary
Q: Convert 11110011₂ (8-bit two’s complement) to decimal.
Steps / Answer
1. Leftmost bit = 1 → negative number.
2. To find magnitude: invert bits → 00001100. Add 1 → 00001101 = 13.
3. So value = −13.
Final: 11110011₂ = −13₁₀
9) Bitmap Image File Size
Q: Calculate file size (in bytes and MB) of an uncompressed 1920 × 1080 image with 24-bit
colour depth.
Steps / Answer
1. Pixels = 1920 × 1080 = 2,073,600 pixels.
2. Colour depth = 24 bits per pixel → total bits = 2,073,600 × 24 = 49,766,400 bits.
3. Convert to bytes: 49,766,400 ÷ 8 = 6,220,800 bytes.
4. Convert to megabytes (SI 1 MB = 1,000,000 bytes): 6,220,800 ÷ 1,000,000 ≈ 6.2208
MB.
Final: ≈ 6,220,800 bytes ≈ 6.22 MB (uncompressed).
10) Sound File Size (mono/stereo)
Q: A 3-minute stereo audio file, sampled at 44.1 kHz with 16-bit depth. Calculate file size in
MB.
Steps / Answer
1. Sample rate = 44,100 samples/sec. Bit depth = 16 bits/sample.
2. Bits per second per channel = 44,100 × 16 = 705,600 bits/s.
3. Stereo → multiply by 2 → 1,411,200 bits/s.
4. Duration = 3 minutes = 180 s → total bits = 1,411,200 × 180 = 254,016,000 bits.
5. Convert to bytes: ÷ 8 = 31,752,000 bytes.
6. Convert to MB (SI): ÷ 1,000,000 ≈ 31.752 MB.
Final: ≈ 31.75 MB (uncompressed stereo PCM).
11) Storage Units — GiB → Bytes / MB
Q: Convert 2 GiB to bytes and to MB (both MiB and decimal MB).
Steps / Answer
1. 1 GiB = 2³⁰ bytes = 1,073,741,824 bytes.
2. 2 GiB = 2 × 1,073,741,824 = 2,147,483,648 bytes.
3. In MiB (binary megabytes): 1 MiB = 2²⁰ bytes = 1,048,576 bytes → 2 GiB = 2048 MiB.
4. In decimal MB (SI): 2,147,483,648 ÷ 1,000,000 ≈ 2147.483648 MB.
Final: 2 GiB = 2,147,483,648 bytes = 2048 MiB ≈ 2147.48 MB.
12) Short conceptual — MAC vs IP address
Q: What is the difference between a MAC address and an IP address?
Answer (brief)
● MAC address: hardware (physical) address assigned to a network interface by the
manufacturer, usually 48 bits shown in hex groups (e.g., 00:1C:B3:4F:25:FE).
Permanent (burned into NIC). Used for local network communication.
● IP address: logical (network) address assigned to a device on a network (IPv4 or IPv6).
Used for routing between networks; can be dynamic or static.