毎回調べてい気がするのでメモ
#include <iostream> #include <bitset> int main() { std::bitset<8> rline[2200] = {0}; std::bitset<10> rout[2200] = {0}; //init for(int i=0;i<1920;i++) { rline[i] = 0x50; } int cnt = -2; for(int i=0;i<1920;i++) { std::cout << rline[i]; int n0 = 0; int n1 = 0; if((rline[i].count() >= 5) || ((rline[i].count() == 4) && (rline[i][0] == 0))) { //XNOR std::cout << " XNOR\t"; bool x = rline[i][0]; bool y; for(int j=0;j<=7;j++) { if(j!=7){y = rline[i][j+1];} rout[i][j] = x; x = !(x^y); } rout[i][8] = 0; rout[i][9] = 0; n1 = rout[i].count(); n0 = rout[i].size() - n1; n0 -= 2; std::cout << rout[i] <<"\t" << n1 << "\t" << cnt << "\t"; } else { //XOR std::cout << " XOR\t"; bool x = rline[i][0]; bool y; for(int j=0;j<=7;j++) { if(j!=7){y = rline[i][j+1];} rout[i][j] = x; x = (x^y); } rout[i][8] = 1; rout[i][9] = 0; n1 = rout[i].count(); n0 = rout[i].size() - n1; n0--; n1--; std::cout << rout[i] <<"\t" << n1 << "\t" << cnt << "\t"; } if((cnt == 0) || (n1 == 4)) { rout[i][9] = ~rout[i][8]; if(rout[i][9]) { rout[i] = ~rout[i]; rout[i][8] = false; rout[i][9] = true; cnt = cnt + n0 - n1; } else { cnt = cnt - (n0 - n1); } } else { if(((cnt > 0) && (n1 > 4))||((cnt < 0)&&(n1 < 4))) { bool tmp = rout[i][8]; rout[i] = ~rout[i]; rout[i][8] = tmp; rout[i][9] = true; if(!rout[i][8]) { cnt = cnt + (n0 - n1); } else { cnt = cnt + (n0 - n1) +2; } } else { rout[i][9] = false; if(!rout[i][8]) { cnt = cnt + (n1 - n0) - 2; } else { cnt = cnt + n1 - n0; } } } std::cout << rout[i] << "\t" << cnt << std::endl ; } return 0; }
参考にしたサイト
http://ijarcet.org/wp-content/uploads/IJARCET-VOL-4-ISSUE-4-1576-1579.pdf
だが最後が少し間違っている。
Disp=disp+onesX-zerosX-zerosX
のところを
Disp=disp+onesX-zerosX
であるはず。