#include #include int crc_check(std::vector bitseq) //int crc_check(unsigned int *frame_plus_fcs,int nbits) // Returns zero if there are no bit errors in the frame. // The input is an array of nbits bits that includes the data // frame followed by the Frame Check Sequence (FCS). The array // of bits is divided by the polynomial x^11 + x^9 + 1 (i.e. the // bit pattern 101000000001). If the result is zero, then there // are no errors in the frame. The frame should be a sequence of // 11-bit words. { int reg[11]; for (int ibit=0; ibit<11; ibit++) reg[ibit] = 0; std::vector::iterator iter; for (iter = bitseq.begin(); iter != bitseq.end(); iter++) { int carry = reg[10]; reg[10] = reg[9]; reg[9] = carry^reg[8]; // Exclusive OR reg[8] = reg[7]; reg[7] = reg[6]; reg[6] = reg[5]; reg[5] = reg[4]; reg[4] = reg[3]; reg[3] = reg[2]; reg[2] = reg[1]; reg[1] = reg[0]; reg[0] = carry^(*iter); // Exclusive OR } int sum = 0; for (ibit=0; ibit<11; ibit++) sum += reg[ibit]; std::cout << "sum:" << sum << endl; return sum; }