Advertisement
ivan_yosifov

Binary Algorithms

Sep 6th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.18 KB | None | 0 0
  1. // Count ones in binary number ex. 5 (101) -> 2
  2. public static int countOnes(int number){
  3.     int count = 0;
  4.     while(number != 0){
  5.         number &= number - 1;
  6.         count++;
  7.     }
  8.     return count;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement