Even Bit Counter

Bit Manipulation Easy Coding Parity

Problem: Even Bit Counter

Write a function that determines whether the number of 1 bits in the binary representation of a given integer is even.

Details

  • Given an integer n, count the number of bits that are set to 1 (i.e., the bits that are 1 in its binary representation).
  • Return true if this count is even; otherwise, return false.

Examples

  • For n = 5 (binary 101), the number of 1 bits is 2, so the output should be true.
  • For n = 7 (binary 111), the number of 1 bits is 3, so the output should be false.

Hint

Use bit manipulation techniques such as bit masking or shifting operations to solve this problem efficiently.

Optional Note: On March 21st, many cultures welcome the balance of light and darkness during the spring equinox. Similarly, your challenge is to check if the balance (parity) of set bits is even.