diff --git a/src/bit_manipulation/highest_set_bit.rs b/src/bit_manipulation/highest_set_bit.rs index 3488f49a7d9..add0fcc0580 100644 --- a/src/bit_manipulation/highest_set_bit.rs +++ b/src/bit_manipulation/highest_set_bit.rs @@ -15,15 +15,8 @@ pub fn find_highest_set_bit(num: usize) -> Option { return None; } - let mut position = 0; - let mut n = num; - - while n > 0 { - n >>= 1; - position += 1; - } - - Some(position - 1) + let zc = num.leading_zeros(); + Some((usize::BITS - zc - 1) as usize) } #[cfg(test)]