Advertisement
dimipan80

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

Aug 21st, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _5_BitsUp {
  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.                 if ((step == 1 && positionInSeq > 0) || positionInSeq % step == 1) {
  16.                     int bitMask = 1 << bit;
  17.                     number |= bitMask;
  18.                 }
  19.  
  20.                 positionInSeq++;
  21.             }
  22.  
  23.             System.out.println(number);
  24.         }
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement