Loading RustViz Engine...
Count number of set bits (1s) in a u32 using Brian Kernighan bit manipulation.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn hamming_weight(mut n: u32) -> u32 {
let mut count = 0;
while n != 0 {
n &= n - 1;
count += 1;
}
count
}