Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ps2;
- import java.util.ArrayList;
- import java.util.Scanner;
- import com.sun.javafx.collections.IntegerArraySyncer;
- public class zad1 {
- public static void main(String[] args) {
- System.out.println("Podaj wielomian");
- String s1 = new Scanner(System.in).nextLine();
- System.out.println("Podaj ziarno");
- String s2 = new Scanner(System.in).nextLine();
- int size = s1.length();
- int wielomian = Integer.parseInt(s1, 2);
- int seed = Integer.parseInt(s2, 2);
- ArrayList<Integer> one_position = new ArrayList<>();
- for (int a = 0; a < size; a++)
- if (((wielomian >> a) & 1) == 1)
- one_position.add(a);
- for (int a = 0; a < 9; a++) {
- int liczba = seed >> 1;
- int wynik = (seed >> one_position.get(0)) & 1;
- for (int b = 1; b < one_position.size(); b++)
- wynik = ((seed >> one_position.get(b)) & 1) ^ wynik;
- if (wynik == 1)
- liczba = liczba | (1 << size - 1);
- else
- liczba = liczba & ~(1 << size - 1);
- seed = liczba;
- System.out.println((String.format("%" + size + "s", Integer.toBinaryString(seed))).replace(' ', '0'));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement