Write a python function to Count Set Bits in a Number
Topic: Write a python function to Count Set Bits in a Number
Solution
def count_set_bits(n): count = 0 while n: n &= n - 1 count += 1 return count
List all Python Programs
Solution
def count_set_bits(n): count = 0 while n: n &= n - 1 count += 1 return count