
Smart Photoionization Detector Module PIDS3
User Manual
PIDS3 - User Manual (en) - 1.03.docx
Analytical Control Instruments GmbH, Volmerstraße 9A, 12489 Berlin, Germany, www.aci-berlin.com
Page 33 of 58
11.1.1
Checksum calculation
The checksum is calculated over the bytes in message section.
Code example (C#):
public
static
uint
Crc32 (
byte
[] buffer,
uint
offset,
uint
count )
{
const
uint
polynomial = 0xEDB88320;
uint
crc =
uint
.MaxValue;
for
(
uint
index = offset; index < count; index++ )
{
crc ^= buffer[index];
for
(
uint
bit = 0; bit < 8; bit++)
{
crc = (crc >> 1) ^ (crc & 1) * polynomial;
}
}
return
~crc;
}
Code example (C or C++):
uint32_t Crc32 (
const
void
* buffer, uint32_t offset, uint32_t count )
{
const
uint32_t polynomial = 0xEDB88320;
uint32_t crc = 0xFFFFFFFF;
uint8_t* src = &((uint8_t*) buffer)[offset];
while
( count-- )
{
crc ^= *src++;
for
( uint32_t bit = 0; bit < 8; bit++ )
{
crc = ( crc >> 1 ) ^ ( crc & 1 ) * polynomial;
}
}
return
~crc;
}