You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
271 B
12 lines
271 B
3 years ago
|
fn count(bits: usize) -> u32 {
|
||
|
let num_bits = usize::BITS;
|
||
|
num_bits as u32 - bits.leading_zeros() + 1
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
println!("{}", count(0b111));
|
||
|
println!("{}", count(0b1111_1111));
|
||
|
println!("{}", count(64)); // 1000000
|
||
|
println!("{}", 1 >> 1);
|
||
|
}
|