Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created March 29, 2018 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/4989a15a9b7a47eb9e9b4516125be517 to your computer and use it in GitHub Desktop.
Save kunigami/4989a15a9b7a47eb9e9b4516125be517 to your computer and use it in GitHub Desktop.
fn first_non_zero_bit_position(input: u32) -> u32 {
let mut remaining: u32 = input;
let mut first_non_zero: u32 = 1;
while (remaining & 1) == 0 && remaining > 1 {
remaining /= 2;
first_non_zero += 1;
}
first_non_zero
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment