#include "stdalg.h" #ifdef STDALGO_CRC7 unsigned char crc7(unsigned char* bytes, unsigned char size) { register unsigned char val = 0; // last cycles value register unsigned char cb; // current byte. unsigned char i; for(i=0; i<=size; i++) { cb = bytes[i]; int q = (i==size) ? 7 : 8; // counter do { val <<= 1; if(cb & 0x80) // check MSB of current byte ++val; // overflow, add 1 if(val & 0x80) // check MSB of (last) seed val ^= 0x9; // polynome cb <<= 1; } while(--q); val &= 0x7f; // lower 7 bits } return ((val<<1) + 1); } #endif