Compute parity bit
Java
Hard
5 views
Problem Description
Task: return 0 if number of set bits is even, 1 if odd.
Output Format
Return value
Constraints
Use XOR folding.
Official Solution
static int parity(int x){int p=0;while(x!=0){p^=1;x&=(x-1);}return p;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!