GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 2.12

Counting set bits using hexadecimal

Digital Logic · Number Systems & Computer Arithmetic · Full GATE CSE 1995 paper

GATE 1995, Q2.12 2 marks · MCQ
Report issue

Number Systems & Computer Arithmetic

Question 2.12, GATE 1995: Count ones in the binary representation of 3·4096+15·256+5·16−3 in GFG; the alternate prints +3.
Tap to enlarge
Your answer
Answer & solution

Answer: C: 10 (no official key was published)

Before subtracting three, the number is hexadecimal 3F50. Subtracting gives 3F4D, whose nibbles 0011,1111,0100,1101 contain 2+4+1+3=10 ones. Thus the answer happens to agree despite the different arithmetic expressions. The subtraction borrows from the previous nibble; treating its low digit as an independent negative digit would not give a binary representation.

Original paper, page 4