def count_set_bits(n):
    """ Returns the number of set bits in the input. """
    count = 0
    while n != 0:
        last_bit = n & 1
        if last_bit == 1:
            count += 1
        n = n >> 1
    return count