Structural deformable models
Main Page
Namespaces
Classes
Files
File List
File Members
src
crc.h
Go to the documentation of this file.
1
/* -*- C++ -*- */
2
/* obtained from: http://www.geocities.com/CapeCanaveral/Launchpad/3632/crc_c.htm */
3
/*****************************************
4
crc.c - straightforward 16 bit CRC
5
by Alberto Ricci Bitti
6
released to public domain
7
8
compatibility notes:
9
works on little-endian machines only,
10
assumes 32 bit long integers,
11
16 bit integers and 8 byte characters
12
*****************************************/
13
14
#ifndef _CRC_H_
15
#define _CRC_H_
16
17
/*crc-16 standard root*/
18
19
#define POLYNOMIAL 0x8005
20
21
/*place your own here*/
22
#define INITIAL_VALUE 0x0000
23
24
namespace
crc
{
25
26
union
{
27
unsigned
long
Whole
;
28
struct
29
{
30
unsigned
char
Data
;
31
unsigned
short
Remainder
;
32
unsigned
char
Head
;
33
}
Part
;
34
}
CRC_buffer
;
35
36
/*internal use only - puts a byte*/
37
38
inline
void
PutCRC
(
unsigned
char
b)
39
{
40
using namespace
crc
;
41
unsigned
char
i;
42
CRC_buffer
.Part.Data = b;
43
for
(i=0; i<8; i++)
44
{
45
CRC_buffer
.Whole =
CRC_buffer
.Whole << 1;
46
if
(
CRC_buffer
.Part.Head & 0x01)
47
CRC_buffer
.Part.Remainder ^=
POLYNOMIAL
;
48
}
49
}
50
};
// end of namespace crc
51
52
53
/*call this routine with your own data buffer*/
54
/* yes! it's really that simple!*/
55
56
inline
unsigned
short
CRC
(
const
unsigned
char
*
Data
,
57
unsigned
int
Length)
58
{
59
using namespace
crc
;
60
CRC_buffer
.Part.Remainder =
INITIAL_VALUE
;
61
while
(Length-- > 0)
62
PutCRC
(*Data++);
63
PutCRC
(0);
64
PutCRC
(0);
65
return
CRC_buffer
.Part.Remainder;
66
}
67
68
#endif
crc
Definition:
crc.h:24
crc::Head
unsigned char Head
Definition:
crc.h:32
crc::Whole
unsigned long Whole
Definition:
crc.h:27
POLYNOMIAL
#define POLYNOMIAL
Definition:
crc.h:19
crc::Remainder
unsigned short Remainder
Definition:
crc.h:31
CRC
unsigned short CRC(const unsigned char *Data, unsigned int Length)
Definition:
crc.h:56
crc::CRC_buffer
union crc::@2 CRC_buffer
crc::Data
unsigned char Data
Definition:
crc.h:30
crc::Part
struct crc::@2::@3 Part
crc::PutCRC
void PutCRC(unsigned char b)
Definition:
crc.h:38
INITIAL_VALUE
#define INITIAL_VALUE
Definition:
crc.h:22
Generated by
1.8.11