Advertisement
veselinsavov

Problem 8. * Count of Equal Bit Pairs

Sep 8th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _8_Problem {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.                 Scanner input = new Scanner(System.in);
  8.        
  9.         int n = input.nextInt();
  10.         int countBits = 0;
  11.            
  12.         while (n > 0){
  13.                 int last2Bits = (n >> 32) & 3; // 3 in binnary is 11
  14.                 if (last2Bits == 0 || last2Bits == 3)
  15.                 {                  
  16.                     countBits++;                   
  17.                 }
  18.                 n = n >> 1;
  19.             }  
  20.         System.out.println(countBits);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement