Skip to content

Instantly share code, notes, and snippets.

@agreensh
Created March 31, 2020 17:37
Show Gist options
  • Select an option

  • Save agreensh/a932a2aac77c4f1ee93de2bc2296c12c to your computer and use it in GitHub Desktop.

Select an option

Save agreensh/a932a2aac77c4f1ee93de2bc2296c12c to your computer and use it in GitHub Desktop.
void main() {
print(numberOfDivisionsByTwo(64));
print(numberOfDivisionsByTwo(66));
print(numberOfDivisionsByTwo(768));
print(numberOfDivisionsByTwo(5));
print(numberOfDivisionsByTwo(2));
print(numberOfDivisionsByTwo(0));
}
int numberOfDivisionsByTwo(int num) {
if (num == 0 || num % 2 != 0) {
return 0;
}
String binaryString = num.toRadixString(2);
int len = binaryString.length;
return(len - binaryString.lastIndexOf('1') - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment