The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
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 in Programming by Active (2.9k points)
retagged by | 77 views

Related questions

0 votes
0 answers
6
0 votes
0 answers
7
asked Jan 18, 2017 in Probability by Sheshang Active (3.3k points) | 103 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,588 questions
54,197 answers
187,536 comments
71,152 users