Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 2, 2008, 12:38:26 PM (16 years ago)
Author:
rgrieder
Message:

Moved all util classes and functions to orxonox namespace.
Converted all code to 4 spaces/tab in util.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/util/CRC32.cc

    r1791 r2111  
    2929#include "CRC32.h"
    3030
     31namespace 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      }
    3141
    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}
    3459
    35     hbit=(crc32 & 0x80000000) ? 1 : 0;
    36     if (hbit != bit)
    37       crc32=(crc32<<1) ^ UTIL_CRC32POLY;
    38     else
    39       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 bit
    46       calcCRCBit(crc32, (data[i]&0x2)>>1); // 2nd bit
    47       calcCRCBit(crc32, (data[i]&0x3)>>2); // 3rd bit
    48       calcCRCBit(crc32, (data[i]&0x4)>>3); // 4th bit
    49       calcCRCBit(crc32, (data[i]&0x5)>>4); // 5th bit
    50       calcCRCBit(crc32, (data[i]&0x6)>>5); // 6th bit
    51       calcCRCBit(crc32, (data[i]&0x7)>>6); // 7th bit
    52       calcCRCBit(crc32, (data[i]&0x8)>>7); // 8th bit
    53     }
    54     return crc32;
    55   }
    56 
Note: See TracChangeset for help on using the changeset viewer.