Geeksforgeeks

Error

×

Given an integer **N**, find it's parity.

Parity of a number refers to the number of 1 bits it contains. The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits.

**Example 1:**

Input:N =13Output:oddExplanation:(13)_{10}= (1101)_{2}The binary representation has three 1-bits. So, it's parity is odd.

**Example 2:**

Input:N =9Output:evenExplanation:(9)_{10}= (1001)_{2}The binary representation has two 1-bits. So, it's parity is even.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **computeParity()** which takes an Integer N as input parameter and returns string "odd" or "even".

**Expected Time Complexity:** O(log(N))

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Parity of unsigned integer

...