1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
/*
* File crc8_c.c
*
* from diorama-1.1.1 by A. Dittrich & T. Schorr
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void crc8_c( /*@out@ */ double checksum[], double in[], int N)
{
int i;
unsigned int b = 0xFF;
unsigned int x = 0x1D; /* (1) 00011101 */
unsigned int y;
for (i = 0; i < N; i++)
{
y = ((b >> 7) + (int) floor(in[i] + 0.5)) & 0x01;
if (y == 1)
b = ((b << 1) ^ x);
else
b = (b << 1);
}
*checksum = (double) (b & 0xFF);
}
|