0 votes
77 views

Consider the following code.

def brian(n):
count = 0
while ( n != 0 )
n = n & ( n-1 )
count = count + 1
return count

Here n is meant to be an unsigned integer. The operator & considers its arguments in binary and computes their bit wise AND.
What does the function brian return?

(A) The highest power of 2 dividing n, but zero if n is zero.

(B) The number obtained by complementing the binary representation of n.

(C) The number of ones in the binary representation of n.

(D) The code might go into an infinite loop for some n

closed as a duplicate of: TIFR2014-B-2
asked
retagged | 77 views

0 votes
1 answer
1
0 votes
0 answers
2
0 votes
0 answers
3
0 votes
0 answers
5
0 votes
0 answers
6
0 votes
0 answers
7