Find Unset Bits
EasyPractice library · +10 XPbit manipulationbeginner
Given a non-negative integer N, determine the number of zero bits (unset bits) in its binary representation. Assume integers are represented using a sufficient number of bits to hold N.
Input
A single non-negative integer N.
Output
A single integer representing the count of zero bits in the binary representation of N.
Constraints
0 <= N <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
10
Output
2
Binary representation of 10 is 1010. It has two 0s.
Example 2
Input
7
Output
0
Binary representation of 7 is 111. It has zero 0s.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
10
Example 2 input
7