optional · CSS study notes
13. Number Systems & Digital Logic
FPSC CSS Computer Science past papers (2016–2026) — 4 questions: 0 MCQs, 4 subjective parts. Newest first.
Part A — Subjective Questions
2025 · Paper-I · Q2(c) (8 marks)
Question
What are Two's Complement numbers? Explain the working of it with examples. Discuss the practical scenarios where these numbers are used.
Solution
Two's complement is the standard binary representation used by computers to store signed (positive and negative) integers. For an n-bit number, the two's complement of a value x is obtained by inverting all bits of |x| (one's complement) and adding 1. The most significant bit acts as the sign bit (0 = positive, 1 = negative).
Example (8-bit representation of -5): 5 in binary = 00000101 Invert bits (one's complement) = 11111010 Add 1 → 11111011 → this is -5 in two's complement.
Verification by addition (5 + (-5) should equal 0): 00000101 (+5)
- 11111011 (-5)
100000000 → discard the 9th carry bit → 00000000 = 0 ✔
Range for n bits: -2^(n-1) to 2^(n-1) - 1 (e.g., for 8 bits: -128 to +127), and there is only a single representation of zero (00000000), unlike sign-magnitude or one's complement.
Practical uses:
- All modern CPU ALUs use two's complement so that subtraction can be done by simple addition (a - b = a + (-b)), needing only an adder circuit, not separate subtractor hardware.
- Used in registers, integer arithmetic, embedded systems and DSP fixed-point arithmetic.
- Simplifies overflow detection and comparison logic since there is a single zero and consistent bit patterns for negative numbers.
2020 · Paper-I · Q2(a) (8 marks)
Question
Write a C/C++ program which implements binary logical 'AND', 'OR' and 'NOT' gates. The program takes binary numbers and desired logical gate as inputs and outputs the desired output of the gate.
Solution
#include <iostream>
using namespace std;
int main() {
int a, b;
char gate;
cout << "Enter first binary digit (0/1): ";
cin >> a;
cout << "Enter operation (A=AND, O=OR, N=NOT): ";
cin >> gate;
if (gate == 'N' || gate == 'n') {
int result = !a;
cout << "NOT " << a << " = " << result << endl;
} else {
cout << "Enter second binary digit (0/1): ";
cin >> b;
int result;
if (gate == 'A' || gate == 'a') result = a && b;
else if (gate == 'O' || gate == 'o') result = a || b;
else { cout << "Invalid gate!" << endl; return 1; }
cout << a << " " << gate << " " << b << " = " << result << endl;
}
return 0;
}
Sample run: input 1, A, 0 -> output 1 A 0 = 0.
2018 · Paper-I · Q2(f) (2 marks)
Question
Ali is telling Ahmad that he is representing a -ve number and its most significant bit is 1, Ahmad immediately shouted you are representing numbers using 2's compliment. True or False. And why?
Solution
This statement, as commonly intended in this exam context, is considered True. In two's complement representation (the standard way modern computers represent signed integers), the most significant bit (MSB) always acts as the sign bit: MSB = 0 indicates a positive number, and MSB = 1 always indicates a negative number. So observing a negative number with MSB = 1 is consistent with, and indicative of, two's complement representation being used - since two's complement is by far the standard/default signed representation used in virtually all modern computer systems. (Strictly speaking, sign-magnitude and one's complement representations also use MSB=1 for negative numbers, so MSB=1 alone doesn't uniquely prove two's complement in a purely logical sense - but since two's complement is the representation universally used by real computer hardware today, Ahmad's inference is considered correct/True in practice.)
2016 · Paper-I · Q4(b) (6 marks)
Question
Convert given binary numbers to Decimal, Octal and Hexadecimal. (i) 100(2) (ii) 10100(2) (iii) 100101(2)
Solution
(i) 100(2): Decimal = 1x4+0x2+0x1 = 4(10). Octal = 4(8). Hexadecimal = 4(16).
(ii) 10100(2): Decimal = 1x16+0x8+1x4+0x2+0x1 = 20(10). Octal: 20/8 = 2 remainder 4 -> 24(8). Hexadecimal: 20/16 = 1 remainder 4 -> 14(16).
(iii) 100101(2): Decimal = 1x32+0x16+0x8+1x4+0x2+1x1 = 37(10). Octal: 37/8 = 4 remainder 5 -> 45(8). Hexadecimal: 37/16 = 2 remainder 5 -> 25(16).
Summary table:
- 100(2) = 4(10) = 4(8) = 4(16)
- 10100(2) = 20(10) = 24(8) = 14(16)
- 100101(2) = 37(10) = 45(8) = 25(16)