Подсчет кусочков в стиле кернигана

// Counting bits Kernighan style
fn bit_count(mut n: usize) -> usize {
    let mut cnt = 0;
    while n > 0 {
        n &= n - 1;
        cnt += 1;
    }
    cnt
}

fn main() {
    println!("Bit count = {} ", bit_count(254));
}
Mackerel