Changeset 2111 for code/branches/objecthierarchy/src/util/CRC32.cc
- Timestamp:
- Nov 2, 2008, 12:38:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/util/CRC32.cc
r1791 r2111 29 29 #include "CRC32.h" 30 30 31 namespace orxonox 32 { 33 void calcCRCBit(uint32_t &crc32, int bit) 34 { 35 int hbit = (crc32 & 0x80000000) ? 1 : 0; 36 if (hbit != bit) 37 crc32 = (crc32 << 1) ^ UTIL_CRC32POLY; 38 else 39 crc32 = crc32 << 1; 40 } 31 41 32 void calcCRCBit(uint32_t &crc32, int bit){ 33 int hbit; 42 uint32_t calcCRC(unsigned char *data, unsigned int dataLength) 43 { 44 uint32_t crc32 = 0; 45 for(unsigned int i = 0; i < dataLength; i++) 46 { 47 calcCRCBit(crc32, (data[i] & 0x1) >> 0); // 1st bit 48 calcCRCBit(crc32, (data[i] & 0x2) >> 1); // 2nd bit 49 calcCRCBit(crc32, (data[i] & 0x3) >> 2); // 3rd bit 50 calcCRCBit(crc32, (data[i] & 0x4) >> 3); // 4th bit 51 calcCRCBit(crc32, (data[i] & 0x5) >> 4); // 5th bit 52 calcCRCBit(crc32, (data[i] & 0x6) >> 5); // 6th bit 53 calcCRCBit(crc32, (data[i] & 0x7) >> 6); // 7th bit 54 calcCRCBit(crc32, (data[i] & 0x8) >> 7); // 8th bit 55 } 56 return crc32; 57 } 58 } 34 59 35 hbit=(crc32 & 0x80000000) ? 1 : 0;36 if (hbit != bit)37 crc32=(crc32<<1) ^ UTIL_CRC32POLY;38 else39 crc32=crc32<<1;40 }41 42 uint32_t calcCRC(unsigned char *data, unsigned int dataLength){43 uint32_t crc32=0;44 for(unsigned int i=0; i<dataLength; i++){45 calcCRCBit(crc32, (data[i]&0x1)>>0); // 1st bit46 calcCRCBit(crc32, (data[i]&0x2)>>1); // 2nd bit47 calcCRCBit(crc32, (data[i]&0x3)>>2); // 3rd bit48 calcCRCBit(crc32, (data[i]&0x4)>>3); // 4th bit49 calcCRCBit(crc32, (data[i]&0x5)>>4); // 5th bit50 calcCRCBit(crc32, (data[i]&0x6)>>5); // 6th bit51 calcCRCBit(crc32, (data[i]&0x7)>>6); // 7th bit52 calcCRCBit(crc32, (data[i]&0x8)>>7); // 8th bit53 }54 return crc32;55 }56
Note: See TracChangeset
for help on using the changeset viewer.