Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program to count how many sequences of two equal bits ("00" or "11")
- * can be found in the binary representation of given integer number n (with overlapping). */
- import java.util.Scanner;
- public class _08_CountOfEqualBitPairs {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter a Integer number: ");
- int number = scan.nextInt();
- int equalBitsCounter = 0;
- while (number != 0) {
- int twoBitsValue = number & 3;
- if (twoBitsValue == 0 || twoBitsValue == 3) {
- equalBitsCounter++;
- }
- number >>>= 1;
- }
- System.out.println("The Count of Equal bit pairs in that number is: " + equalBitsCounter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement