CSS Prepare

optional · CSS study notes

I.15 Information Representation & Number Systems

⬆️ Back to: P-I.I. Introduction to Computing

🧭

Page Outline — click a heading to jump. Past-paper questions sit in the last section.

🎯

Exam pattern (2016–2026): 2016 Q4(b) · 2018 Q2(f) · 2019 Q5(c) · 2020 Q2(a) · 2021 Q3(d) · 2025 Q2(c). Six questions in six different years — the most-asked page in this chapter.


Number Systems

  • Binary (Base 2): uses only the digits 0 and 1.
    • Definition: the native number system of digital computers — each binary digit (bit) maps directly to one of two physical states (on/off, high/low voltage).
    • How it's used: all data, instructions, and addresses are ultimately stored and processed in binary inside the hardware.
    • Example: (1100)₂ = 12 in decimal.
  • Octal (Base 8): uses digits 0–7.
    • Definition: each octal digit represents exactly 3 binary bits, since 2³ = 8.
    • How it's used: a compact shorthand for binary, historically used in older computing systems; still seen in Unix file permission notation (e.g., chmod 755).
    • Example: (17)₈ = 15 in decimal.
  • Decimal (Base 10): uses digits 0–9.
    • Definition: the standard number system humans use day to day; not native to computer hardware.
    • How it's used: numbers are converted to/from binary at the human–computer boundary so users can work in a familiar system.
    • Example: (156)₁₀.
  • Hexadecimal (Base 16): uses digits 0–9 plus letters A–F (representing values 10–15).
    • Definition: each hex digit represents exactly 4 binary bits (a nibble), since 2⁴ = 16.
    • How it's used: a compact, human-readable stand-in for binary — used for memory addresses, colour codes (e.g., #FF0000), and error codes.
    • Example: (9C)₁₆ = 156 in decimal.

Conversions

General Rule (Positional Notation)

Every number system works on the same underlying equation — this is the one formula that explains every conversion below:

  • Formula: N = dₙ×bⁿ + ... + d₁×b¹ + d₀×b⁰ (+ d₋₁×b⁻¹ + ... for fractional digits)
    • where b = the base (2 for binary, 8 for octal, 10 for decimal, 16 for hex) and dᵢ = the digit at position i, counted from 0 at the rightmost digit.
  • This single formula IS "any base → decimal" conversion; converting decimal → any base is just the reverse process (repeated division).

1. Decimal → Binary (Base 10 → Base 2)

  • Method: repeated division by 2, reading remainders bottom-to-top.
  • Worked example: convert (156)₁₀ → binary
    • 156 ÷ 2 = 78, remainder 0
    • 78 ÷ 2 = 39, remainder 0
    • 39 ÷ 2 = 19, remainder 1
    • 19 ÷ 2 = 9, remainder 1
    • 9 ÷ 2 = 4, remainder 1
    • 4 ÷ 2 = 2, remainder 0
    • 2 ÷ 2 = 1, remainder 0
    • 1 ÷ 2 = 0, remainder 1
    • Read remainders bottom-to-top: (156)₁₀ = (10011100)₂

2. Binary → Decimal (Base 2 → Base 10)

  • Formula: N₁₀ = Σ (bitᵢ × 2ⁱ)
  • Worked example: convert (10011100)₂ → decimal
    • = 1×2⁷ + 0×2⁶ + 0×2⁵ + 1×2⁴ + 1×2³ + 1×2² + 0×2¹ + 0×2⁰
    • = 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = (156)₁₀

3. Decimal → Octal (Base 10 → Base 8)

  • Method: repeated division by 8, reading remainders bottom-to-top.
  • Worked example: convert (156)₁₀ → octal
    • 156 ÷ 8 = 19, remainder 4
    • 19 ÷ 8 = 2, remainder 3
    • 2 ÷ 8 = 0, remainder 2
    • Read bottom-to-top: (156)₁₀ = (234)₈

4. Octal → Decimal (Base 8 → Base 10)

  • Formula: N₁₀ = Σ (digitᵢ × 8ⁱ)
  • Worked example: convert (234)₈ → decimal
    • = 2×8² + 3×8¹ + 4×8⁰ = 128 + 24 + 4 = (156)₁₀

5. Decimal → Hexadecimal (Base 10 → Base 16)

  • Method: repeated division by 16, reading remainders bottom-to-top (remainders 10-15 become A-F).
  • Worked example: convert (156)₁₀ → hex
    • 156 ÷ 16 = 9, remainder 12 = C
    • 9 ÷ 16 = 0, remainder 9
    • Read bottom-to-top: (156)₁₀ = (9C)₁₆

6. Hexadecimal → Decimal (Base 16 → Base 10)

  • Formula: N₁₀ = Σ (digitᵢ × 16ⁱ)
  • Worked example: convert (9C)₁₆ → decimal
    • = 9×16¹ + 12×16⁰ (C = 12) = 144 + 12 = (156)₁₀

7. Binary ↔ Octal (direct, no decimal step needed)

  • Rule: 1 octal digit = exactly 3 binary bits (since 2³ = 8) — group bits into 3s from the right (binary→octal) or expand each octal digit into 3 bits (octal→binary).
  • Worked example (binary → octal): (10011100)₂ → pad to a multiple of 3 = 010 011 100 → groups = 2, 3, 4 → (234)₈
  • Worked example (octal → binary): (234)₈ → 2=010, 3=011, 4=100 → (010011100)₂

8. Binary ↔ Hexadecimal (direct, no decimal step needed)

  • Rule: 1 hex digit = exactly 4 binary bits (a nibble, since 2⁴ = 16) — group bits into 4s from the right (binary→hex) or expand each hex digit into 4 bits (hex→binary).
  • Worked example (binary → hex): (10011100)₂ → groups of 4 = 1001, 1100 → 9, C → (9C)₁₆
  • Worked example (hex → binary): (9C)₁₆ → 9=1001, C=1100 → (10011100)₂

9. Fractional Decimal → Binary (Bonus — occasionally tested)

  • Method: repeatedly multiply the fractional part by 2; the integer part of each result (0 or 1) becomes the next binary digit, read top-to-bottom this time (opposite direction from the integer method).
  • Worked example: convert (0.375)₁₀ → binary
    • 0.375 × 2 = 0.75 → integer part 0
    • 0.75 × 2 = 1.5 → integer part 1
    • 0.5 × 2 = 1.0 → integer part 1
    • Read top-to-bottom: (0.375)₁₀ = (0.011)₂
  • Why examiners like this one: it's the mirror image of the integer method — multiply instead of divide, and read the digits in the opposite order (top-to-bottom, not bottom-to-top).

10. Converting a Full Decimal Number (Integer + Fraction) to Binary

  • Method: split the number at the decimal point, convert each part with its own method, then join the results with a binary point.
    • Integer part → repeated division by 2, read remainders bottom-to-top (Method 1 above).
    • Fractional part → repeated multiplication by 2, read integer parts top-to-bottom (Method 9 above).
  • Worked example: convert (25.75)₁₀ → binary
    • Integer part (25):
      • 25 ÷ 2 = 12, remainder 1
      • 12 ÷ 2 = 6, remainder 0
      • 6 ÷ 2 = 3, remainder 0
      • 3 ÷ 2 = 1, remainder 1
      • 1 ÷ 2 = 0, remainder 1
      • Read bottom-to-top → 25 = 11001₂
    • Fractional part (0.75):
      • 0.75 × 2 = 1.5 → integer part 1, carry forward 0.5
      • 0.5 × 2 = 1.0 → integer part 1, remainder 0 → stop (fraction became exactly 0)
      • Read top-to-bottom → 0.75 = .11₂
    • Join the two parts at the binary point → (25.75)₁₀ = (11001.11)₂
  • Exam angle: always convert the integer and fractional parts separately (different method, different reading direction for each), then simply join them with a binary point — don't try to force one single method across the whole number.
  • Why conversions matter for the exam: base conversion questions test whether a candidate understands why grouping/positional-value works (powers of the base lining up with place values), not just memorized steps — always show the working, not just the final answer.

Extra Practice Set — A Second Number Through Every Rule

Same 9 rules as above, worked through a second number (89, and 0.8125 for the fractional rule) so you can check your own practice attempts.

  • Decimal → Binary: (89)₁₀ → 89÷2=44 r1; 44÷2=22 r0; 22÷2=11 r0; 11÷2=5 r1; 5÷2=2 r1; 2÷2=1 r0; 1÷2=0 r1 → read bottom-to-top → (1011001)₂
  • Binary → Decimal: (1011001)₂ = 1×2⁶+0×2⁵+1×2⁴+1×2³+0×2²+0×2¹+1×2⁰ = 64+0+16+8+0+0+1 = (89)₁₀
  • Decimal → Octal: (89)₁₀ → 89÷8=11 r1; 11÷8=1 r3; 1÷8=0 r1 → read bottom-to-top → (131)₈
  • Octal → Decimal: (131)₈ = 1×8²+3×8¹+1×8⁰ = 64+24+1 = (89)₁₀
  • Decimal → Hexadecimal: (89)₁₀ → 89÷16=5 r9; 5÷16=0 r5 → read bottom-to-top → (59)₁₆
  • Hexadecimal → Decimal: (59)₁₆ = 5×16¹+9×16⁰ = 80+9 = (89)₁₀
  • Binary → Octal: (1011001)₂ → pad to multiple of 3 = 001 011 001 → groups = 1, 3, 1 → (131)₈
  • Octal → Binary: (131)₈ → 1=001, 3=011, 1=001 → (001011001)₂
  • Binary → Hexadecimal: (1011001)₂ → pad to multiple of 4 = 0101 1001 → groups = 5, 9 → (59)₁₆
  • Hexadecimal → Binary: (59)₁₆ → 5=0101, 9=1001 → (01011001)₂
  • Fractional Decimal → Binary: (0.8125)₁₀ → 0.8125×2=1.625→1; 0.625×2=1.25→1; 0.25×2=0.5→0; 0.5×2=1.0→1 → read top-to-bottom → (0.8125)₁₀ = (0.1101)₂

Bonus Note: Prime Factorization Method (HCF & LCM)

Not strictly a number-system topic, but a general-math number technique worth keeping alongside base conversions.

  • Prime factorization: writing a number as a product of only its prime factors.
    • Example: 36 = 2×2×3×3 = 2²×3²
  • HCF (Highest Common Factor) by prime factorization
    • Method: prime-factorize each number, then multiply together only the common prime factors, each raised to its lowest power among the numbers.
    • Worked example: HCF(36, 48)
      • 36 = 2²×3²
      • 48 = 2⁴×3¹
      • Common primes: 2 and 3 → lowest powers: 2² and 3¹
      • HCF = 2²×3 = 4×3 = 12
  • LCM (Least Common Multiple) by prime factorization
    • Method: prime-factorize each number, then multiply together every prime factor that appears (common or not), each raised to its highest power among the numbers.
    • Worked example: LCM(36, 48)
      • Primes involved: 2 and 3 → highest powers: 2⁴ (from 48) and 3² (from 36)
      • LCM = 2⁴×3² = 16×9 = 144
  • Quick self-check: HCF × LCM = product of the two original numbers.
    • Check: 36×48 = 1728, and 12×144 = 1728 ✓ — if this doesn't match, a factorization step was likely wrong.
  • Exam angle: state clearly whether you're taking the lowest power (HCF) or highest power (LCM) of each common prime — this is the single most common source of HCF/LCM mix-ups.

Data Representation

UnitSize
BitSmallest unit — a single 0 or 1
Byte8 bits — enough to represent one character
Kilobyte (KB)~1024 bytes
Megabyte (MB)~1024 KB
Gigabyte (GB)~1024 MB
Terabyte (TB)~1024 GB

Character Encoding

  • ASCII: a 7-bit (extended to 8-bit) encoding scheme covering 128 (or 256) characters — English letters, digits, and basic punctuation/control codes.
    • How it works: assigns each character a fixed numeric code (e.g., 'A' = 65); simple and fast but cannot represent non-English scripts.
    • Use case: legacy systems, plain English text, simple data interchange.
  • Unicode / UTF-8: a variable-width encoding standard designed to represent every character in every major world script (Arabic, Urdu, Chinese, emoji, etc.).
    • How it works: UTF-8 uses 1 to 4 bytes per character — common ASCII characters still fit in 1 byte (backward-compatible with ASCII), while other scripts use more bytes as needed.
    • Use case: the modern default for web pages, multilingual documents, and international software — a common exam contrast against ASCII's English-only limitation.

BCD (Binary Coded Decimal)

  • Definition: encodes each individual decimal digit (0-9) as its own separate 4-bit binary code, instead of converting the whole number to binary at once.
  • How it works: split the decimal number into digits, then replace each digit with its 4-bit binary equivalent.
    • Worked example (decimal → BCD): convert (47)₁₀ → BCD
      • 4 = 0100, 7 = 0111 → BCD = 0100 0111
    • Worked example (BCD → decimal): decode 0111 1001
      • 0111 = 7, 1001 = 9 → decimal = 79
  • Key contrast with straight binary: BCD is NOT the same as converting the full number to binary.
    • (47)₁₀ in BCD = 0100 0111 (each digit separately)
    • (47)₁₀ in straight binary = 101111 (the whole number converted at once) — these look completely different.
  • Valid codes: only 0000-1001 (0-9) are valid BCD digit codes; 1010-1111 (10-15) are never used and are invalid in BCD.
  • Variants:
    • Packed BCD: two digits stored per byte (one per nibble) — more storage-efficient.
    • Unpacked BCD: one digit per byte (the extra nibble often left zero or used for a sign) — simpler but wastes more space.
  • Pros/Cons: makes conversion to/from human-readable decimal display trivial, and avoids the rounding errors straight binary has with some decimal fractions (e.g., 0.1 has no exact binary representation) — important for financial/monetary calculations; but wastes storage (a 4-bit nibble can represent 16 values yet only 10 are used) and is slower/less efficient for arithmetic than pure binary.
  • Use case: digital clocks, calculators, cash registers/POS systems, and financial software needing exact decimal rounding.

Signed Number Representation

Computers must represent both positive and negative numbers using only 0s and 1s. All three schemes below reserve the leftmost (most significant) bit as the sign bit (0 = positive, 1 = negative) but differ in how the magnitude/negative value is stored.

1. Sign-Magnitude

  • Definition: the leftmost bit is a pure sign flag; the remaining bits store the magnitude in ordinary binary, unchanged.
  • Worked example (8-bit, representing 5 and −5):
    • +5 → sign bit 0 + magnitude 0000101 → 00000101
    • −5 → sign bit 1 + the same magnitude 0000101 → 10000101
  • Decoding: read the leftmost bit for sign, then read the rest as a plain binary magnitude.
  • Drawback: produces two representations of zero (+0 = 00000000, −0 = 10000000), and arithmetic circuits are more complex since sign and magnitude must be handled separately.

2. 1's Complement

  • Definition: a negative number is formed by inverting (flipping) every bit of its positive binary form.
  • Encoding method — worked example: represent −5 in 8-bit 1's complement
    • Start from +5 = 00000101
    • Invert every bit (0→1, 1→0) → 11111010 = −5 in 1's complement
  • Decoding method — worked example: what value does 11111010 represent?
    • Leftmost bit = 1 → the number is negative
    • Invert every bit → 00000101 = 5
    • So the value is −5
  • Drawback: like sign-magnitude, it still has two representations of zero (+0 = 00000000, −0 = 11111111), complicating arithmetic logic.

3. 2's Complement (the standard used by real computers)

  • Definition: a negative number is formed by inverting every bit of the positive form and then adding 1.
  • Encoding method — worked example: represent −5 in 8-bit 2's complement
    • Start from +5 = 00000101
    • Invert every bit (1's complement step) → 11111010
    • Add 1 → 11111011 = −5 in 2's complement
  • Decoding method — worked example: what value does 11111011 represent?
    • Leftmost bit = 1 → the number is negative
    • Invert every bit → 00000100
    • Add 1 → 00000101 = 5
    • So the value is −5 (same procedure as encoding — invert, then add 1, works both ways)
  • Why it's standard: gives a single, unique representation of zero and allows addition/subtraction to be done with the same simple binary-adder circuitry regardless of sign — this is why virtually all modern computers use 2's complement to store negative integers.
  • Range (n-bit 2's complement): from −2ⁿ⁻¹ to +2ⁿ⁻¹−1 — e.g., 8-bit range is −128 to +127 (one extra negative value compared with sign-magnitude/1's-complement, because there's no wasted −0 code).

Overflow in Signed Number Arithmetic

  • Definition: overflow occurs when the result of an arithmetic operation falls outside the representable range for the number of bits used, producing an incorrect (wrapped-around) result.
  • Overflow rule (2's complement addition): overflow can happen only when adding two numbers of the same sign.
    • Two positives added together give a result that looks negative → overflow.
    • Two negatives added together give a result that looks positive → overflow.
    • Adding numbers of different signs can never overflow — the result always fits.
  • Worked example — positive overflow: add (100)₁₀ + (50)₁₀ in 8-bit 2's complement (max representable is +127)
    • 100 = 01100100, 50 = 00110010
    • Sum (binary addition) = 10010110
    • The result's sign bit is 1 (looks negative), but two positive operands can never truly sum to a negative number → overflow (the true sum, 150, doesn't fit in the −128..+127 range).
  • Worked example — negative overflow: add (−100)₁₀ + (−50)₁₀ (min representable is −128)
    • −100 = 10011100, −50 = 11001110
    • Sum (binary addition, discarding the carry out of the 8th bit) = 01101001
    • The result's sign bit is 0 (looks positive), but two negative operands can never truly sum to a positive number → overflow (the true sum, −150, doesn't fit in the −128..+127 range).
  • Non-overflow example: (−5)₁₀ + (3)₁₀ = −2 — operands have different signs, so overflow is impossible here regardless of the result.
  • Carry vs Overflow (don't confuse these): a carry out of the leftmost (sign) bit is a fact about unsigned addition and does not by itself mean overflow; overflow is specifically about the signed result being wrong. The formal detection rule: overflow occurs exactly when the carry into the sign bit differs from the carry out of the sign bit.

Binary Arithmetic: 1's Complement, 2's Complement & Subtraction

🎯

CSS exam angle: "Perform binary subtraction using 1's / 2's complement" is one of the most repeated short numericals (see also Arithmetic Microprocessor in Paper II). Always show every step: the complement, the column addition, the carry decision, and the decimal check. The check line alone often earns a mark.

1. Binary Addition Rules (needed for every method below)

A + BSumCarry
0 + 000
0 + 1 / 1 + 010
1 + 101
1 + 1 + 1 (with carry-in)11

2. Finding the 1's and 2's Complement — Quick Methods

  • 1's complement: flip every bit (0→1, 1→0). 00001101 → 11110010
  • 2's complement (method A): 1's complement + 1. 11110010 + 1 → 11110011
  • 2's complement (method B, exam shortcut): start from the right, copy every bit up to and including the first 1, then flip all the bits to its left.
    • 00011000 → the first 1 from the right is the 4th bit → copy 1000, flip 0001 → 1110 → 11101000
    • 01010000 → copy 10000, flip 010 → 101 → 10110000
  • Always fix the bit-width first. Complements are only defined for a fixed number of bits: pad both numbers with leading 0s to the same length (8 bits is the safe default in the exam) before complementing.

3. Method 1 — Direct Subtraction (with Borrow)

Rules: 0−0 = 0 · 1−0 = 1 · 1−1 = 0 · 0−1 = 1, borrow 1 from the next column on the left.

Example: 25 − 13

  1 1 0 0 1     (25)
− 0 1 1 0 1     (13)
-----------
  0 1 1 0 0     (12)  ✓
  • Bit 0: 1−1 = 0 · Bit 1: 0−0 = 0 · Bit 2: 0−1 → borrow → 10−1 = 1
  • Bit 3: 1 became 0 after lending; 0−1 → borrow → 1 · Bit 4: 1 became 0; 0−0 = 0
  • Drawback: needs a separate subtractor circuit. Complement methods let the same adder do subtraction, which is why computers use them.

4. Method 2 — Subtraction Using 1's Complement

📌

Rule for A − B: (1) Take the 1's complement of B. (2) Add it to A. (3) Look at the carry out of the leftmost bit:

  • Carry = 1 → the answer is positive. Add the carry back to the rightmost bit (end-around carry).
  • Carry = 0 → the answer is negative. Take the 1's complement of the sum and put a − sign in front.

Case 1 (A > B): 25 − 13, 8-bit

A          =   0 0 0 1 1 0 0 1   (25)
1's of 13  = + 1 1 1 1 0 0 1 0   (13 = 00001101, flipped)
             -----------------
           1   0 0 0 0 1 0 1 1   ← carry = 1
end-around carry          +   1
             -----------------
               0 0 0 0 1 1 0 0   = +12  ✓

Case 2 (A < B): 13 − 25, 8-bit

A          =   0 0 0 0 1 1 0 1   (13)
1's of 25  = + 1 1 1 0 0 1 1 0   (25 = 00011001, flipped)
             -----------------
           0   1 1 1 1 0 0 1 1   ← carry = 0 → negative
1's complement of result →  0 0 0 0 1 1 0 0 = 12  →  answer = −12  ✓

5. Method 3 — Subtraction Using 2's Complement (the one computers use)

📌

Rule for A − B: (1) Take the 2's complement of B. (2) Add it to A. (3) Look at the carry out of the leftmost bit:

  • Carry = 1 → the answer is positive. Simply discard the carry.
  • Carry = 0 → the answer is negative. Take the 2's complement of the sum and put a − sign in front.

Case 1 (A > B): 25 − 13, 8-bit

A          =   0 0 0 1 1 0 0 1   (25)
2's of 13  = + 1 1 1 1 0 0 1 1   (13 = 00001101 → 11110010 + 1)
             -----------------
           1   0 0 0 0 1 1 0 0   ← carry = 1 → discard
answer     =   0 0 0 0 1 1 0 0   = +12  ✓

Case 2 (A < B): 13 − 25, 8-bit

A          =   0 0 0 0 1 1 0 1   (13)
2's of 25  = + 1 1 1 0 0 1 1 1   (25 = 00011001 → 11100110 + 1)
             -----------------
           0   1 1 1 1 0 1 0 0   ← carry = 0 → negative
2's complement of result →  0 0 0 0 1 1 0 0 = 12  →  answer = −12  ✓

Case 3 (signed operands, result already in 2's complement form): (−12) − (−5)

  • Subtracting −5 is the same as adding +5: −12 = 11110100, +5 = 00000101
  • 11110100 + 00000101 = 11111001. The sign bit is 1, so it is negative: 2's complement → 00000111 = 7 → −7 ✓
  • When the numbers are already stored as signed 2's complement values, the sum is the answer; the carry rule above is for subtracting two unsigned magnitudes.

6. 1's vs 2's Complement Subtraction — Comparison

Point1's complement method2's complement method
Complement of BFlip all bitsFlip all bits, then add 1
If carry = 1Add it back (end-around carry)Discard it
If carry = 0Negative: take 1's complement of the resultNegative: take 2's complement of the result
Representations of zeroTwo (+0 and −0)One
Extra addition stepYes (the end-around carry)No
Used in real CPUsRarelyYes, universal

7. General Form — r's and (r−1)'s Complement

  • For base r with n digits: r's complement of N = rⁿ − N · (r−1)'s complement of N = (rⁿ − 1) − N
  • Binary (r = 2): 2's and 1's complement · Decimal (r = 10): 10's and 9's complement
  • Decimal example: 72532 − 3250. 10's complement of 03250 = 100000 − 3250 = 96750. 72532 + 96750 = 169282 → discard the carry → 69282 ✓
  • Same logic as binary: carry = 1 means positive, discard it; carry = 0 means negative, take the complement.

8. Practice Set (answers in the toggle)

  1. Find the 1's and 2's complement of 00101100.
  2. 45 − 28 using direct subtraction.
  3. 45 − 28 using 1's complement (8-bit).
  4. 28 − 45 using 1's complement (8-bit).
  5. 45 − 28 using 2's complement (8-bit).
  6. 28 − 45 using 2's complement (8-bit).
  7. 5 − 7 using 2's complement (4-bit).
  • ✅ Answers (attempt first)
    1. 1's = 11010011 · 2's = 11010100 (shortcut: copy 100 from the right, flip 00101 → 11010)
    2. 101101 − 011100 = 010001 = 17
    3. 1's of 28 = 11100011 → 00101101 + 11100011 = 1 00010000 → carry 1, add back → 00010001 = +17
    4. 1's of 45 = 11010010 → 00011100 + 11010010 = 0 11101110 → no carry → 1's complement → 00010001 → −17
    5. 2's of 28 = 11100100 → 00101101 + 11100100 = 1 00010001 → discard carry → 00010001 = +17
    6. 2's of 45 = 11010011 → 00011100 + 11010011 = 0 11101111 → no carry → 2's complement → 00010001 → −17
    7. 2's of 0111 = 1001 → 0101 + 1001 = 0 1110 → no carry → 2's complement → 0010 → −2

9. Mistakes That Lose Marks

  • Complementing without first padding both numbers to the same bit-width
  • Adding the carry back in the 2's method (that is only for 1's)
  • Discarding the carry in the 1's method (it must be added back)
  • Forgetting the − sign when there is no carry
  • Skipping the decimal check: always write "25 − 13 = 12 ✓" at the end

Worked Example

  • Convert (156)₁₀ to binary: 156 ÷ 2 repeatedly → 156=10011100₂; grouping into nibbles (1001 1100) gives hex 9C₁₆

MCQ Traps

  • 2's complement is the standard method computers use to represent negative integers — don't confuse with 1's complement or sign-magnitude.
  • Sign-magnitude and 1's complement both have two representations of zero (+0 and −0); 2's complement fixes this — a frequently tested distinguishing fact.
  • Decoding a 2's complement negative number uses the same steps as encoding (invert all bits, then add 1) — students sometimes wrongly assume decoding needs a different procedure.
  • 8-bit 2's complement range is −128 to +127, not −127 to +127 — the range is asymmetric because 2's complement has no wasted −0 code, giving one extra negative value.
  • Overflow can only happen when adding two numbers of the same sign — adding a positive and a negative number can never cause overflow, a frequently tested rule.
  • Carry-out and overflow are different concepts — a carry out of the sign bit does not automatically mean overflow; overflow is detected by comparing carry-in vs carry-out of the sign bit, not by the carry-out alone.
  • 1 hex digit = 4 bits and 1 octal digit = 3 bits — these grouping sizes are often swapped in distractor options.
  • Binary↔octal and binary↔hex can be done directly by grouping bits — you do NOT need to convert through decimal first; going via decimal is slower and only needed for decimal↔other-base conversions.
  • Decimal→binary uses division + read remainders bottom-to-top; fractional decimal→binary uses multiplication + read results top-to-bottom — the direction of reading is a commonly reversed exam trap.
  • ASCII is fixed/narrow (English only); Unicode/UTF-8 is variable-width and covers all world scripts — a common exam contrast, and UTF-8 is backward-compatible with ASCII for the first 128 characters.
  • BCD encodes each decimal digit separately — it is NOT the same as converting the whole number to straight binary. Comparing (47)₁₀ in BCD (0100 0111) vs straight binary (101111) is a classic exam trap.
  • Valid BCD codes only run 0000-1001 — any nibble from 1010-1111 appearing in "BCD" data signals an invalid/error code.

📜 Past-Paper Questions & MCQs (CSS 2016–2026)

2016 · Paper-I · Q4(b) · 6 marks

Q. Convert the binary numbers to decimal, octal and hexadecimal: (i) 100₂ (ii) 10100₂ (iii) 100101₂.

Quick revision — key points

  • Decimal: expand using powers of two
  • Octal: group binary bits in threes from the right
  • Hexadecimal: group binary bits in fours from the right
  • Show intermediate workings for all three binary inputs

Exam-ready worked solution (6 marks): We use positional weights for decimal, groups of three bits for octal, and groups of four bits for hexadecimal. Group from the right, adding leading zeros only when needed.

(i) (100)₂

  1. Binary to decimal: 1002=1×22+0×21+0×20=410100_2 = 1\times2^2 + 0\times2^1 + 0\times2^0 = 4_{10}.
  2. Binary to octal: Split into three-bit groups: 100. This group has value 4, so 1002=48100_2 = 4_8.
  3. Binary to hexadecimal: Pad to four bits: 0100. This group is 4, so 1002=416100_2 = 4_{16}.
  4. Check: All three are equivalent to decimal 4.

(ii) (10100)₂

  1. Binary to decimal: 1×24+0×23+1×22+0×21+0×20=16+4=20101\times2^4 + 0\times2^3 + 1\times2^2 + 0\times2^1 + 0\times2^0 = 16+4=20_{10}.
  2. Binary to octal: Group right to left: 10 | 100. Pad the incomplete left group: 010 | 100. Convert separately: 010 = 2; 100 = 4. Hence (24)₈.
  3. Binary to hexadecimal: Group: 1 | 0100 → 0001 | 0100. Convert: 0001 = 1; 0100 = 4. Hence (14)₁₆.
  4. Verify: (24)8=2×8+4=20(24)_8 = 2\times8+4=20; (14)16=1×16+4=20(14)_{16}=1\times16+4=20.

(iii) (100101)₂

  1. Binary to decimal: 1×25+0×24+0×23+1×22+0×21+1×20=32+4+1=37101\times2^5+0\times2^4+0\times2^3+1\times2^2+0\times2^1+1\times2^0=32+4+1=37_{10}.
  2. Binary to octal: Group: 100 | 101. Convert: 100 = 4 and 101 = 5. Hence (45)₈.
  3. Binary to hexadecimal: Group: 10 | 0101 → pad → 0010 | 0101. Convert: 0010 = 2; 0101 = 5. Hence (25)₁₆.
  4. Verify: (45)8=4×8+5=37(45)_8=4\times8+5=37 and (25)16=2×16+5=37(25)_{16}=2\times16+5=37.

Exam presentation: Show each positional expansion and each grouping step. The final values alone do not demonstrate the conversion method.

2018 · Paper-I · Q2(f) · 2 marks

Q. Ali says he is representing a negative number whose most significant bit is 1. Ahmad shouts "you are using 2's complement". True or false? Why?

Quick revision + exam-ready answer

Quick revision — key points

  • False: MSB 1 is not exclusive to two's complement
  • Sign-magnitude and ones' complement also use 1 for negative
  • Unsigned bit patterns can begin with 1

Exam-ready answer

False. In a signed two's-complement representation the most significant bit indicates a negative value, but a leading 1 can also occur in sign-magnitude and ones'-complement representations, and in ordinary unsigned values. The bit pattern alone does not identify the encoding; the representation convention must be known.

2019 · Paper-I · Q5(c) · 5 marks

Q. An image is a representation of some information. Discuss how a computer represents an image internally. Name different algorithms used to extract features from images.

Quick revision + exam-ready answer

Quick revision — key points

  • Raster image is pixel matrix
  • Explain grayscale and RGB channel values
  • Mention bit depth and pixel dimensions
  • Algorithms: Sobel/Canny, Harris, SIFT/ORB/HOG

Exam-ready answer — structured

Introduction / direct answer: A digital image is a two-dimensional array of pixels.

Main explanation

  • A monochrome image may store one intensity per pixel, while RGB images commonly store red, green and blue channel values; an 8-bit-per-channel RGB pixel offers 256 intensity levels per channel. Resolution (width × height) indicates pixel count, while bit depth determines available intensity precision.
  • Feature extraction turns raw pixels into useful descriptors. Examples include Sobel or Canny edge detection, Harris corner detection, SIFT, SURF, ORB and HOG features.
  • Convolutional neural networks learn hierarchical image features automatically. Example: edge and corner features can help distinguish a road sign from the background.

2020 · Paper-I · Q2(a) · 8 marks

Q. Write a C/C++ program which implements binary logical AND, OR and NOT gates. The program takes binary numbers and the desired logical gate as inputs and outputs the result of the gate.

Quick revision + exam-ready answer

Quick revision — key points

  • Provide AND/OR/NOT truth tables
  • Read and validate 0/1 inputs
  • Use conditional or switch logic in C++
  • Demonstrate one sample run

Exam-ready answer (8 marks)

Approach: The program reads the selected gate and valid binary input bits. AND and OR require two inputs, whereas NOT requires one input.

Logic-gate truth table

ABA AND BA OR BNOT A
00001
01011
10010
11110

C++ implementation

#include <iostream>
using namespace std;

int main() {
    int a, b = 0;
    char gate;
    cout << "Enter gate (& for AND, | for OR, ! for NOT): ";
    cin >> gate;

    if (gate != '&' && gate != '|' && gate != '!') {
        cout << "Invalid gate";
        return 1;
    }

    cout << "Enter first bit (0 or 1): ";
    cin >> a;
    if (a != 0 && a != 1) {
        cout << "Invalid binary input";
        return 1;
    }

    if (gate == '&' || gate == '|') {
        cout << "Enter second bit (0 or 1): ";
        cin >> b;
        if (b != 0 && b != 1) {
            cout << "Invalid binary input";
            return 1;
        }
    }

    switch (gate) {
        case '&': cout << (a && b); break;
        case '|': cout << (a || b); break;
        case '!': cout << (!a); break;
    }
    return 0;
}

Sample executions

  1. Gate &, inputs 1 and 0 → 0 (AND is true only if both bits are 1).
  2. Gate |, inputs 1 and 0 → 1 (OR is true if at least one input is 1).
  3. Gate !, input 0 → 1 (NOT reverses the bit).

Conclusion: The program implements all three logic gates, validates input bits and produces outputs consistent with their truth tables.

8-mark presentation: State the approach, include a truth table, provide the complete program and show at least one sample run.

2021 · Paper-I · Q3(d) · 4 marks

Q. Write a program in C/C++ to convert a decimal number to hexadecimal.

Quick revision + exam-ready answer

Quick revision — key points

  • Repeatedly divide decimal by 16
  • Map remainders 10–15 to A–F
  • Reverse the remainder order
  • C++ program and dry run, handle zero

Exam-ready answer — structured

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    unsigned int n;
    cin >> n;
    if (n == 0) { cout << "0"; return 0; }
    string digits = "0123456789ABCDEF", ans;
    while (n > 0) {
        ans += digits[n % 16];
        n /= 16;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
}

Introduction / direct answer: Dry run: 254 ÷ 16 = 15 remainder 14 (E); 15 ÷ 16 = 0 remainder 15 (F).

Main explanation

  • Reading remainders backward gives FE₁₆. The sample handles non-negative integers; negative values require a specified representation.

2025 · Paper-I · Q2(c) · 8 marks

Q. What are Two's Complement numbers? Explain the working with examples. Discuss practical scenarios where they are used.

Quick revision + exam-ready answer

Quick revision — key points

  • n-bit signed range −2^(n−1) to 2^(n−1)−1
  • Negate: invert bits then add 1
  • Show binary addition/subtraction example
  • Explain ALU use, unique zero and overflow

Exam-ready answer (8 marks)

Introduction: Two's complement is the most widely used fixed-width binary representation for signed integers. It permits positive and negative integers to be processed through the same binary arithmetic circuitry.

1. Signed range and representation

  • An n-bit two's-complement integer represents values from −2^(n−1) to 2^(n−1) − 1.
  • With 8 bits, the range is −128 to +127. The highest-order bit has a negative positional weight; zero has only one representation.

2. Converting a positive number into its negative

  1. Write the positive number in the selected bit width.
  2. Invert all binary digits (1's complement).
  3. Add 1 and ignore any carry beyond the bit width.

Example: represent −5 using 8 bits

  • +5: 00000101
  • Invert: 11111010
  • Add one: 11111011
  • Hence 11111011 is −5 in 8-bit two's complement.

3. Addition and subtraction

  • To subtract B from A, add the two's-complement form of −B to A.
  • Worked example: 5 − 3
    • +5 = 00000101
    • −3 = 11111101
    • Sum: 1 00000010; discard the carry beyond 8 bits.
    • Result: 00000010 = +2.

4. Practical applications

  1. Arithmetic Logic Units (ALUs): Signed addition and subtraction can share binary adders.
  2. Programming languages: Signed integer types in many modern systems use two's-complement representations.
  3. Embedded systems: Microcontrollers process signed sensor readings such as temperatures below zero.
  4. Digital signal processing: Audio samples and signed measurement values can be represented compactly.

5. Advantages and limitation

  • Advantages: One zero representation, straightforward negation and efficient signed arithmetic.
  • Overflow: An 8-bit signed result outside −128 to +127 cannot be represented correctly; the overflow condition must be detected. The final carry bit alone does not establish signed overflow.

Conclusion: Two's complement provides an efficient and consistent method of representing signed values and performing arithmetic in digital computers.