Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::endl;
- #define MAX_COLUMNS 3
- #define MAX_ROWS 3
- #define MAX_BITS 3
- void move_down(int m[MAX_COLUMNS][MAX_ROWS], int x, int y) {
- static int last[MAX_ROWS] = { -1 };
- static int p[MAX_ROWS] = { 0 };
- static int n[MAX_ROWS] = { 0 };
- if(last[x + n[x]] == -1)
- last[x + n[x]] = m[x + n[x]][y];
- else
- m[x + n[x]][y] = last[x + n[x]];
- if(p[x + n[x]] == MAX_BITS) {
- m[x + n[x]][y] = last[x + n[x]];
- p[x + n[x]] = 0;
- n[x] ++;
- }
- m[x + n[x]][y] |= (0b1 << p[x + n[x]]);
- p[x + n[x]] ++;
- }
- void print_m(int m[MAX_COLUMNS][MAX_ROWS]) {
- int y;
- for(int x = 0; x < MAX_COLUMNS; x++) {
- for(y = 0; y < MAX_ROWS; y++) {
- cout << m[x][y] << ", ";
- }
- cout << endl;
- }
- }
- int main()
- {
- /*
- int matrix[MAX_COLUMNS][MAX_ROWS] = {
- {0b001, 0b010, 0b011, 0b100, 0b101, 0b110},
- {0b010, 0b011, 0b100, 0b101, 0b110, 0b101},
- {0b011, 0b100, 0b101, 0b110, 0b101, 0b100},
- {0b100, 0b101, 0b110, 0b101, 0b100, 0b011},
- {0b101, 0b110, 0b101, 0b100, 0b011, 0b010},
- {0b110, 0b101, 0b100, 0b011, 0b010, 0b001}
- };
- */
- int matrix[MAX_COLUMNS][MAX_ROWS] = { 0 };
- for(int a = 0; a < 6; a++) {
- move_down(matrix, 0, 0);
- print_m(matrix);
- cout << endl << endl;
- }
- int
- a = 0b0001,
- b = 0b0101,
- c = 0b1000;
- cout << (a & b) << endl;
- cout << (a | b) << endl;
- cout << (a ^ b) << endl;
- cout << (a & 0b1) << endl;
- cout << (b & 0b101) << endl;
- cout << (b & (0b1 << 2) ) << endl;
- cout << (c & (0b1 << 3) ) << endl;
- cout << "Ola!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement