Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int last_pos(int k) {
- for(int i=31; i>=0; --i) {
- if ((k & 1<<i) != 0) return i+1;
- }
- return -1;
- }
- string to_s(int k) {
- string x;
- for(int i=31; i>=0; --i) {
- if ((k & 1<<i) != 0) {
- if (i == 0) x += "+1";
- else if (i == 1) x += "+x";
- else
- x += "+x^" + std::to_string(i);
- }
- }
- if (x == "") return "0";
- return x.substr(1, x.size()-1);
- }
- int main () {
- int M = 9;
- // slides int M = 11;
- for(int i=0; i<8; ++i) {
- for(int j=0; j<8; ++j) {
- int c = 0;
- if (i & 1) c ^= j;
- if (i & 2) c ^= (j<<1);
- if (i & 4) c ^= (j<<2);
- while(1) {
- int shift = last_pos(c) - last_pos(M);
- if (shift < 0) break;
- c = c ^ (M <<shift);
- }
- string line = to_s(c);
- printf("%-20s, ", line.c_str());
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement