Advertisement
Guest User

zad1

a guest
Mar 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package ps2;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. import com.sun.javafx.collections.IntegerArraySyncer;
  7.  
  8. public class zad1 {
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         System.out.println("Podaj wielomian");
  13.         String s1 = new Scanner(System.in).nextLine();
  14.         System.out.println("Podaj ziarno");
  15.         String s2 = new Scanner(System.in).nextLine();
  16.         int size = s1.length();
  17.         int wielomian = Integer.parseInt(s1, 2);
  18.         int seed = Integer.parseInt(s2, 2);
  19.  
  20.         ArrayList<Integer> one_position = new ArrayList<>();
  21.         for (int a = 0; a < size; a++)
  22.             if (((wielomian >> a) & 1) == 1)
  23.                 one_position.add(a);
  24.  
  25.         for (int a = 0; a < 9; a++) {
  26.  
  27.             int liczba = seed >> 1;
  28.             int wynik = (seed >> one_position.get(0)) & 1;
  29.  
  30.             for (int b = 1; b < one_position.size(); b++)
  31.                 wynik = ((seed >> one_position.get(b)) & 1) ^ wynik;
  32.  
  33.             if (wynik == 1)
  34.                 liczba = liczba | (1 << size - 1);
  35.             else
  36.                 liczba = liczba & ~(1 << size - 1);
  37.  
  38.             seed = liczba;
  39.  
  40.             System.out.println((String.format("%" + size + "s", Integer.toBinaryString(seed))).replace(' ', '0'));
  41.  
  42.         }
  43.  
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement