Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Count ones in binary number ex. 5 (101) -> 2
- public static int countOnes(int number){
- int count = 0;
- while(number != 0){
- number &= number - 1;
- count++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement