Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int last_pos(int k) {
  5.     for(int i=31; i>=0; --i) {
  6.         if ((k & 1<<i) != 0) return i+1;
  7.     }
  8.     return -1;
  9. }
  10. string to_s(int k) {
  11.     string x;
  12.     for(int i=31; i>=0; --i) {
  13.         if ((k & 1<<i) != 0) {
  14.             if (i == 0) x += "+1";
  15.             else if (i == 1) x += "+x";
  16.             else
  17.                 x += "+x^" + std::to_string(i);
  18.         }
  19.     }
  20.     if (x == "") return "0";
  21.     return x.substr(1,  x.size()-1);
  22. }
  23.  
  24. int main () {
  25.     int M = 9;
  26.     // slides int M = 11;
  27.     for(int i=0; i<8; ++i) {
  28.         for(int j=0; j<8; ++j) {
  29.             int c = 0;
  30.             if (i & 1) c ^= j;
  31.             if (i & 2) c ^= (j<<1);
  32.             if (i & 4) c ^= (j<<2);
  33.             while(1) {
  34.                 int shift = last_pos(c) - last_pos(M);
  35.                 if (shift < 0) break;
  36.                 c = c ^ (M <<shift);
  37.             }
  38.             string line =  to_s(c);
  39.             printf("%-20s, ",  line.c_str());
  40.         }
  41.         cout << endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement