Created
March 31, 2020 17:37
-
-
Save agreensh/a932a2aac77c4f1ee93de2bc2296c12c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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