On February 28, many fields celebrate milestones of precision and reliability. In a similar spirit of precision, your task is to write a function that determines whether an integer has an even or odd parity based on its binary representation. The parity of a number is defined as the evenness or oddness of the count of 1 bits.
Write a function that takes a non-negative integer as input and returns true
if the number of 1 bits (in its binary representation) is even, and false
otherwise.
Input: 5
(binary 101
)
true
Input: 7
(binary 111
)
false
Below is some starter code in multiple languages to help you begin your solution implementation.