Skip to content

ISRO Scientist/Engineer CSE 2018Digital Logic › Number Representation

ISRO Scientist/Engineer CSE 2018 PYQ: If a variable can take only integral values from 0 to $n$, where $n$ is an integer, then the variable can be…

If a variable can take only integral values from 0 to $n$, where $n$ is an integer, then the variable can be represented as a bit-field whose width is $($the log in the answer are to the base 2, and $\left \lceil \log_{}{n} \right \rceil$ means the floor of $\log_{}{n}\ )$

  1. A
    $\left \lceil \log (n) \right \rceil + 1 \text{ bits}$
    Correct answer
  2. B
    $\left \lceil \log (n-1) \right \rceil + 1 \text{ bits}$
  3. C
    $\left \lceil \log (n+1) \right \rceil + 1\text{ bits}$
  4. D
    None of the above

Answer

(A) $\left \lceil \log (n) \right \rceil + 1 \text{ bits}$

Approach

The question explicitly defines the bracket notation ⌈ ⌉ to mean the FLOOR, not the ceiling. So option A is floor(log2 n)+1, which is exactly the bit-width of n and equals ceil(log2(n+1)) — the minimum bits to hold all values 0..n (e.g., n=3→2 bits, n=4→3 bits). Option B, floor(log2(n-1))+1, fails at n=2 (gives 1 bit but 0,1,2 need 2 bits). Option C, floor(log2(n+1))+1, over-counts (n=3 gives 3 bits though 2 suffice). Hence A is the correct, universally valid formula for n≥1.

Reviewed by ISRO IQ Editorial Team.