Bit Parity Checker

Bit Manipulation Parity Coding Easy

Problem: Bit Parity Checker

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.

Task

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.

Example

  • Input: 5 (binary 101)

    • Number of 1 bits: 2 (even)
    • Output: true
  • Input: 7 (binary 111)

    • Number of 1 bits: 3 (odd)
    • Output: false

Notes

  • Try to use bit manipulation techniques rather than converting the number to a string when possible.
  • Aim for a solution that runs efficiently in O(log n) time, where n is the input number.

Starter Code

Below is some starter code in multiple languages to help you begin your solution implementation.