Advertisement
dimipan80

C#Exams 5. Bits Inverter (on Java Code)

Aug 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _5_BitsInverter {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int count = scan.nextInt();
  9.         int step = scan.nextInt();
  10.  
  11.         int positionInSeq = 0;
  12.         for (int i = 0; i < count; i++) {
  13.             int number = scan.nextInt();
  14.             for (int bit = 7; bit >= 0; bit--) {
  15.                 positionInSeq++;
  16.                 if (step == 1 || positionInSeq % step == 1) {
  17.                     int bitMask = 1 << bit;
  18.                     number ^= bitMask;
  19.                 }
  20.             }
  21.  
  22.             System.out.println(number);
  23.         }
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement