//****************************************** *********************
//Here, the polynomial is generated according to the CRC-CCITT standard. CRC-CCITT is a 17-bit generator polynomial
//G=[1 0001 0000 0010 0001], expressed in polynomial form as G(x)=x16+x12
//+x5+1, the check code R generated by it The number of binary digits is 16 bits (2 bytes).
JAVA version:
package crc16_half;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException; < br>public class half_crc {
static byte[] ha00 = {
(byte)0x00,(byte)0x10,(byte)0x20,(byte)0x30,(byte)0x40,(byte)0x50,( byte)0x60,(byte)0x70,(byte)0x81,(byte)0x91,(byte)0xA1,(byte)0xB1,(byte)0xC1,(byte)0xD1,(byte)0xE1,(byte)0xF1, < br> (byte)0x12,(byte)0x02,(byte)0x32,(byte)0x22,(byte)0x52,(byte)0x42,(byte)0x72,(byte)0x62,(byte)0x93,(byte) 0x83,(byte)0xB3,(byte)0xA3,(byte)0xD3,(byte)0xC3,(byte)0xF3,(byte)0xE3,
(byte)0x24,(byte)0x34,(byte)0x04, (byte)0x14,(byte)0x64,(byte)0x74,(byte)0x44,(byte)0x54,(byte)0xA5,(byte)0xB5,(byte)0x85,(byte)0x95,(byte)0xE5, (byte)0xF5,(byte)0xC5,(byte)0xD5,
(byte)0x36,(byte)0x26,(byte)0x16,(byte)0x06,(byte)0x76,(byte)0x66,(byte )0x56,(byte)0x46,(byte)0xB7,(byte)0xA7,(byte)0x97,(byte)0x87,(byte)0xF7,(byte)0xE7,(byte)0xD7,(byte)0xC7,
(Byte)0x48,(byte)0x58,(byte)0x68,(byte)0x78,(byte) 0x08,(byte)0x18,(byte)0x28,(byte)0x38,(byte)0xC9,(byte)0xD9,(byte)0xE9,(byte)0xF9,(byte)0x89,(byte)0x99,(byte) 0xA9,(byte)0xB9,
(byte)0x5A,(byte)0x4A,(byte)0x7A,(byte)0x6A,(byte)0x1A,(byte)0x0A,(byte)0x3A,(byte)0x2A, (byte)0xDB,(byte)0xCB,(byte)0xFB,(byte)0xEB,(byte)0x9B,(byte)0x8B,(byte)0xBB,(byte)0xAB,
(byte)0x6C,(byte )0x7C,(byte)0x4C,(byte)0x5C,(byte)0x2C,(byte)0x3C,(byte)0x0C,(byte)0x1C,(byte)0xED,(byte)0xFD,(byte)0xCD,(byte )0xDD,(byte)0xAD,(byte)0xBD,(byte)0x8D,(byte)0x9D,
(byte)0x7E,(byte)0x6E,(byte)0x5E,(byte)0x4E,(byte)0x3E ,(byte)0x2E,(byte)0x1E,(byte)0x0E,(byte)0xFF,(byte)0xEF,(byte)0xDF,(byte)0xCF,(byte)0xBF,(byte)0xAF,(byte)0x9F ,(byte)0x8F,
(byte)0x91,(byte)0x81,(byte)0xB1,(byte)0xA1,(byte)0xD1,(byte)0xC1,(byte)0xF1,(byte)0xE1,( byte)0x10,(byte)0x00,(byte)0x30,(byte)0x20,(byte)0x50,(byte)0x40,(byte)0x70,(byte)0x60,
(byte)0x83,(byte) 0x93,(byte)0xA3,(byte)0xB3,(byte)0xC3,(byte)0xD3,(byte)0xE3,(byte)0xF3,(byte)0x02,(byte)0x12,(byte )0x22,(byte)0x32,(byte)0x42,(byte)0x52,(byte)0x62,(byte)0x72,
(byte)0xB5,(byte)0xA5,(byte)0x95,(byte)0x85 ,(byte)0xF5,(byte)0xE5,(byte)0xD5,(byte)0xC5,(byte)0x34,(byte)0x24,(byte)0x14,(byte)0x04,(byte)0x74,(byte)0x64 ,(byte)0x54,(byte)0x44,
(byte)0xA7,(byte)0xB7,(byte)0x87,(byte)0x97,(byte)0xE7,(byte)0xF7,(byte)0xC7,( byte)0xD7,(byte)0x26,(byte)0x36,(byte)0x06,(byte)0x16,(byte)0x66,(byte)0x76,(byte)0x46,(byte)0x56,
(byte) 0xD9,(byte)0xC9,(byte)0xF9,(byte)0xE9,(byte)0x99,(byte)0x89,(byte)0xB9,(byte)0xA9,(byte)0x58,(byte)0x48,(byte) 0x78,(byte)0x68,(byte)0x18,(byte)0x08,(byte)0x38,(byte)0x28,
(byte)0xCB,(byte)0xDB,(byte)0xEB,(byte)0xFB, (byte)0x8B,(byte)0x9B,(byte)0xAB,(byte)0xBB,(byte)0x4A,(byte)0x5A,(byte)0x6A,(byte)0x7A,(byte)0x0A,(byte)0x1A, (byte)0x2A,(byte)0x3A,
(byte)0xFD,(byte)0xED,(byte)0xDD,(byte)0xCD,(byte)0xBD,(byte)0xAD,(byte)0x9D,(byte )0x8D,(byte)0x7C,(byte)0x6C,(byte)0x5C,(byte)0x4C,(byte)0x3C,(byte)0x2C,(byte)0x1C,(byte)0x0C, (byte)0xEF,(byte)0xFF,(byte)0xCF,(byte)0xDF,(byte)0xAF,(byte)0xBF,(byte)0x8F,(byte)0x9F,(byte)0x6E,(byte) 0x7E,(byte)0x4E,(byte)0x5E,(byte)0x2E,(byte)0x3E,(byte)0x0E,(byte)0x1E);
static byte[] la00 = {
(byte)0x00,(byte)0x21,(byte)0x42,(byte)0x63,(byte)0x84,(byte)0xA5,(byte)0xC6,(byte)0xE7,(byte)0x08,(byte)0x29, (byte)0x4A,(byte)0x6B,(byte)0x8C,(byte)0xAD,(byte)0xCE,(byte)0xEF,
(byte)0x31,(byte)0x10,(byte)0x73,(byte )0x52,(byte)0xB5,(byte)0x94,(byte)0xF7,(byte)0xD6,(byte)0x39,(byte)0x18,(byte)0x7B,(byte)0x5A,(byte)0xBD,(byte )0x9C,(byte)0xFF,(byte)0xDE,
(byte)0x62,(byte)0x43,(byte)0x20,(byte)0x01,(byte)0xE6,(byte)0xC7,(byte)0xA4 ,(byte)0x85,(byte)0x6A,(byte)0x4B,(byte)0x28,(byte)0x09,(byte)0xEE,(byte)0xCF,(byte)0xAC,(byte)0x8D,
( byte)0x53,(byte)0x72,(byte)0x11,(byte)0x30,(byte)0xD7,(byte)0xF6,(byte)0x95,(byte)0xB4,(byte)0x5B,(byte)0x7A,( byte)0x19,(byte)0x38,(byte)0xDF,(byte)0xFE,(byte)0x9D,(byte)0xBC,
(byte)0xC4,( byte)0xE5,(byte)0x86,(byte)0xA7,(byte)0x40,(byte)0x61,(byte)0x02,(byte)0x23,(byte)0xCC,(byte)0xED,(byte)0x8E,( byte)0xAF,(byte)0x48,(byte)0x69,(byte)0x0A,(byte)0x2B,
(byte)0xF5,(byte)0xD4,(byte)0xB7,(byte)0x96,(byte) 0x71,(byte)0x50,(byte)0x33,(byte)0x12,(byte)0xFD,(byte)0xDC,(byte)0xBF,(byte)0x9E,(byte)0x79,(byte)0x58,(byte) 0x3B,(byte)0x1A,
(byte)0xA6,(byte)0x87,(byte)0xE4,(byte)0xC5,(byte)0x22,(byte)0x03,(byte)0x60,(byte)0x41, (byte)0xAE,(byte)0x8F,(byte)0xEC,(byte)0xCD,(byte)0x2A,(byte)0x0B,(byte)0x68,(byte)0x49,
(byte)0x97,(byte )0xB6,(byte)0xD5,(byte)0xF4,(byte)0x13,(byte)0x32,(byte)0x51,(byte)0x70,(byte)0x9F,(byte)0xBE,(byte)0xDD,(byte )0xFC,(byte)0x1B,(byte)0x3A,(byte)0x59,(byte)0x78,
(byte)0x88,(byte)0xA9,(byte)0xCA,(byte)0xEB,(byte)0x0C ,(byte)0x2D,(byte)0x4E,(byte)0x6F,(byte)0x80,(byte)0xA1,(byte)0xC2,(byte)0xE3,(byte)0x04,(byte)0x25,(byte)0x46 ,(byte)0x67,
(byte)0xB9,(byte)0x98,(byte)0xFB,(byte)0xDA,(byte)0x3D,(byte)0x1C,(byte) 0x7F,(byte)0x5E,(byte)0xB1,(byte)0x90,(byte)0xF3,(byte)0xD2,(byte)0x35,(byte)0x14,(byte)0x77,(byte)0x56,
(byte)0xEA,(byte)0xCB,(byte)0xA8,(byte)0x89,(byte)0x6E,(byte)0x4F,(byte)0x2C,(byte)0x0D,(byte)0xE2,(byte)0xC3, (byte)0xA0,(byte)0x81,(byte)0x66,(byte)0x47,(byte)0x24,(byte)0x05,
(byte)0xDB,(byte)0xFA,(byte)0x99,(byte )0xB8,(byte)0x5F,(byte)0x7E,(byte)0x1D,(byte)0x3C,(byte)0xD3,(byte)0xF2,(byte)0x91,(byte)0xB0,(byte)0x57,(byte )0x76,(byte)0x15,(byte)0x34,
(byte)0x4C,(byte)0x6D,(byte)0x0E,(byte)0x2F,(byte)0xC8,(byte)0xE9,(byte)0x8A ,(byte)0xAB,(byte)0x44,(byte)0x65,(byte)0x06,(byte)0x27,(byte)0xC0,(byte)0xE1,(byte)0x82,(byte)0xA3,
( byte)0x7D,(byte)0x5C,(byte)0x3F,(byte)0x1E,(byte)0xF9,(byte)0xD8,(byte)0xBB,(byte)0x9A,(byte)0x75,(byte)0x54,( byte)0x37,(byte)0x16,(byte)0xF1,(byte)0xD0,(byte)0xB3,(byte)0x92,
(byte)0x2E,(byte)0x0F,(byte)0x6C,(byte) 0x4D,(byte)0xAA,(byte)0x8B,(byte)0xE8,(byte)0xC9,(byte)0x26,(byte)0x07,(byte)0x64,(byte)0x45, (byte)0xA2,(byte)0x83,(byte)0xE0,(byte)0xC1,
(byte)0x1F,(byte)0x3E,(byte)0x5D,(byte)0x7C,(byte)0x9B,(byte )0xBA,(byte)0xD9,(byte)0xF8,(byte)0x17,(byte)0x36,(byte)0x55,(byte)0x74,(byte)0x93,(byte)0xB2,(byte)0xD1,(byte )0xF0
};
private static int get_crc16_ccitt(byte[] data, int len) {
int a =data[0] & 0x00ff;
int b =data[1 ] & 0x00ff;
int c =data[2] & 0x00ff;
for(int i=2;i c =((la00[a ]& 0x00ff) ^ c);
a =((ha00[a]& 0x00ff) ^ b);
b = c;
if (i==len-1) break;
c=(data[i+1] & 0x00ff);
}
return ((a & 0x00ff) << 8)|(b & 0x00ff) & 0xffff;
}
public static void main(String[] args) throws IOException {
//String test=”e0e00024333539333639303830343735363135000000000018a920190704155205″;
String test=”CBCAFF191C345EBCA89F0000000000E0E000223335393336393038323434393632 36FFFFFFFFFF81BB1300000012340000362120190704101912″;
byte[] buffer =DatatypeConverter.parseHexBinary(test);
int crc16 = half_crc.get_crc16_ccitt(buffer,buffer.length);
System.out .println(Integer.toHexString(crc16));
}
}
//** ***********
C# version:
static byte[] ha00 = {
0x00,0x10,0x20,0x30,0x40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34,
0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x8,0x8,0x8,0x2F,0x6D,0x8,0x2,0x8 0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x3,0x54,0x75,0x54,0x92 br> 0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,0x9,0xE0,0xC1,0x9,0xE0,0xC1,0x9,0xE0,0xC1,0x9,0x5 ,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
private int get_crc16_ccitt(byte[] static data,
int a = data[0] & 0x00ff;
int b = data[1] & 0x00FF;
INT C = Data [2] & 0x00FF; div>
for (int i = 2; i {
c = ((la00 [a] & 0x00ff) ^ c);
a = ((ha00[a] & 0x00ff) ^ b);
b = c;
if (i == len-1) = (data[i + 1] & 0x00ff);
}
Return ((a & 0x00ff) << 8) | (b & 0x00ff) & 0xff
//************
C++ version:
const unsigned char ha00[256] ={
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12, 0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x14,0x64,0x04,0x14,0x64,0x74,0x44 ,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9,
0x5A,0x4A,0A,0A,0x6 0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,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x38,0xDF,0xFE,0x9D,0xBC,
0xC4,0x0 ,0xA7,0x40,0x61, 0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B,
0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0x 0xBF,0x9E,0x79,0x58,0x3B,0x1A,
0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0 0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78,
0x88,0xA9,0xCA,0xEB,2,0×6,0x ,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67,
0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E, 0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56,
0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81, 0x66,0x47 ,
0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6C8,0x0E,0 ,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x37,0x54,0x37 0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0x3E, <0x5, 0 0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
);
void CRC16_ccitt(unsigned char *a,unsigned char *b, unsigned char *c) {*c = la00[*a] ^ *c; *a = ha00[*a] ^ *b; *b = *c;}
< /p>
package crc16_half;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
public class half_crc {
static byte[] ha00 = {
(Byte)0x00,(byte)0x10,(byte)0x20,(byte)0x30,(byte)0x40,(byte)0x50,(by te)0x60,(byte)0x70,(byte)0x81,(byte)0x91,(byte)0xA1,(byte)0xB1,(byte)0xC1,(byte)0xD1,(byte)0xE1,(byte)0xF1, < br> (byte)0x12,(byte)0x02,(byte)0x32,(byte)0x22,(byte)0x52,(byte)0x42,(byte)0x72,(byte)0x62,(byte)0x93,(byte) 0x83,(byte)0xB3,(byte)0xA3,(byte)0xD3,(byte)0xC3,(byte)0xF3,(byte)0xE3,
(byte)0x24,(byte)0x34,(byte)0x04, (byte)0x14,(byte)0x64,(byte)0x74,(byte)0x44,(byte)0x54,(byte)0xA5,(byte)0xB5,(byte)0x85,(byte)0x95,(byte)0xE5, (byte)0xF5,(byte)0xC5,(byte)0xD5,
(byte)0x36,(byte)0x26,(byte)0x16,(byte)0x06,(byte)0x76,(byte)0x66,(byte )0x56,(byte)0x46,(byte)0xB7,(byte)0xA7,(byte)0x97,(byte)0x87,(byte)0xF7,(byte)0xE7,(byte)0xD7,(byte)0xC7,
(Byte)0x48,(byte)0x58,(byte)0x68,(byte)0x78,(byte)0x08,(byte)0x18,(byte)0x28,(byte)0x38,(byte)0xC9,(byte)0xD9 ,(byte)0xE9,(byte)0xF9,(byte)0x89,(byte)0x99,(byte)0xA9,(byte)0xB9,
(byte)0x5A,(byte)0x4A,(byte)0x7A,( byte)0x6A,(byte)0x1A,(byte)0x0A,(byte)0x3A,(byte)0x2A,(byte)0xDB,(byte)0xCB,(byte)0xFB,(byte)0xEB,(byte)0 x9B,(byte)0x8B,(byte)0xBB,(byte)0xAB,
(byte)0x6C,(byte)0x7C,(byte)0x4C,(byte)0x5C,(byte)0x2C,(byte)0x3C, (byte)0x0C,(byte)0x1C,(byte)0xED,(byte)0xFD,(byte)0xCD,(byte)0xDD,(byte)0xAD,(byte)0xBD,(byte)0x8D,(byte)0x9D,
(byte)0x7E,(byte)0x6E,(byte)0x5E,(byte)0x4E,(byte)0x3E,(byte)0x2E,(byte)0x1E,(byte)0x0E,(byte)0xFF,(byte )0xEF,(byte)0xDF,(byte)0xCF,(byte)0xBF,(byte)0xAF,(byte)0x9F,(byte)0x8F,
(byte)0x91,(byte)0x81,(byte)0xB1 ,(byte)0xA1,(byte)0xD1,(byte)0xC1,(byte)0xF1,(byte)0xE1,(byte)0x10,(byte)0x00,(byte)0x30,(byte)0x20,(byte)0x50 ,(byte)0x40,(byte)0x70,(byte)0x60,
(byte)0x83,(byte)0x93,(byte)0xA3,(byte)0xB3,(byte)0xC3,(byte)0xD3,( byte)0xE3,(byte)0xF3,(byte)0x02,(byte)0x12,(byte)0x22,(byte)0x32,(byte)0x42,(byte)0x52,(byte)0x62,(byte)0x72, < br> (byte)0xB5,(byte)0xA5,(byte)0x95,(byte)0x85,(byte)0xF5,(byte)0xE5,(byte)0xD5,(byte)0xC5,(byte)0x34,(byte) 0x24,(byte)0x14,(byte)0x04,(byte)0x74,(byte)0x64,(byte)0x54,(byte)0x44,
(byte)0xA7,(byte)0xB7,( byte)0x87,(byte)0x97,(byte)0xE7,(byte)0xF7,(byte)0xC7,(byte)0xD7,(byte)0x26,(byte)0x36,(byte)0x06,(byte)0x16,( byte)0x66,(byte)0x76,(byte)0x46,(byte)0x56,
(byte)0xD9,(byte)0xC9,(byte)0xF9,(byte)0xE9,(byte)0x99,(byte) 0x89,(byte)0xB9,(byte)0xA9,(byte)0x58,(byte)0x48,(byte)0x78,(byte)0x68,(byte)0x18,(byte)0x08,(byte)0x38,(byte) 0x28,
(byte)0xCB,(byte)0xDB,(byte)0xEB,(byte)0xFB,(byte)0x8B,(byte)0x9B,(byte)0xAB,(byte)0xBB,(byte)0x4A, (byte)0x5A,(byte)0x6A,(byte)0x7A,(byte)0x0A,(byte)0x1A,(byte)0x2A,(byte)0x3A,
(byte)0xFD,(byte)0xED,(byte )0xDD,(byte)0xCD,(byte)0xBD,(byte)0xAD,(byte)0x9D,(byte)0x8D,(byte)0x7C,(byte)0x6C,(byte)0x5C,(byte)0x4C,(byte )0x3C,(byte)0x2C,(byte)0x1C,(byte)0x0C,
(byte)0xEF,(byte)0xFF,(byte)0xCF,(byte)0xDF,(byte)0xAF,(byte)0xBF ,(byte)0x8F,(byte)0x9F,(byte)0x6E,(byte)0x7E,(byte)0x4E,(byte)0x5E,(byte)0x2E,(byte)0x3E,(byte)0x0E,(byte)0x1E };
static byte[] la00 = {
(byte)0x00,(byte)0x21,(byte)0x42,(byte)0x63,(byte)0x84,(byt e)0xA5,(byte)0xC6,(byte)0xE7,(byte)0x08,(byte)0x29,(byte)0x4A,(byte)0x6B,(byte)0x8C,(byte)0xAD,(byte)0xCE,( byte)0xEF,
(byte)0x31,(byte)0x10,(byte)0x73,(byte)0x52,(byte)0xB5,(byte)0x94,(byte)0xF7,(byte)0xD6,(byte) 0x39,(byte)0x18,(byte)0x7B,(byte)0x5A,(byte)0xBD,(byte)0x9C,(byte)0xFF,(byte)0xDE,
(byte)0x62,(byte)0x43, (byte)0x20,(byte)0x01,(byte)0xE6,(byte)0xC7,(byte)0xA4,(byte)0x85,(byte)0x6A,(byte)0x4B,(byte)0x28,(byte)0x09, (byte)0xEE,(byte)0xCF,(byte)0xAC,(byte)0x8D,
(byte)0x53,(byte)0x72,(byte)0x11,(byte)0x30,(byte)0xD7,(byte )0xF6,(byte)0x95,(byte)0xB4,(byte)0x5B,(byte)0x7A,(byte)0x19,(byte)0x38,(byte)0xDF,(byte)0xFE,(byte)0x9D,(byte) )0xBC,
(byte)0xC4,(byte)0xE5,(byte)0x86,(byte)0xA7,(byte)0x40,(byte)0x61,(byte)0x02,(byte)0x23,(byte)0xCC ,(byte)0xED,(byte)0x8E,(byte)0xAF,(byte)0x48,(byte)0x69,(byte)0x0A,(byte)0x2B,
(byte)0xF5,(byte)0xD4,( byte)0xB7,(byte)0x96,(byte)0x71,(byte)0x50,(byte)0x33,(byte)0x12,(byte)0xFD,(byte)0xDC,(byte)0xBF,(by te)0x9E,(byte)0x79,(byte)0x58,(byte)0x3B,(byte)0x1A,
(byte)0xA6,(byte)0x87,(byte)0xE4,(byte)0xC5,(byte) 0x22,(byte)0x03,(byte)0x60,(byte)0x41,(byte)0xAE,(byte)0x8F,(byte)0xEC,(byte)0xCD,(byte)0x2A,(byte)0x0B,(byte) 0x68,(byte)0x49,
(byte)0x97,(byte)0xB6,(byte)0xD5,(byte)0xF4,(byte)0x13,(byte)0x32,(byte)0x51,(byte)0x70, (byte)0x9F,(byte)0xBE,(byte)0xDD,(byte)0xFC,(byte)0x1B,(byte)0x3A,(byte)0x59,(byte)0x78,
(byte)0x88,(byte )0xA9,(byte)0xCA,(byte)0xEB,(byte)0x0C,(byte)0x2D,(byte)0x4E,(byte)0x6F,(byte)0x80,(byte)0xA1,(byte)0xC2,(byte )0xE3,(byte)0x04,(byte)0x25,(byte)0x46,(byte)0x67,
(byte)0xB9,(byte)0x98,(byte)0xFB,(byte)0xDA,(byte)0x3D ,(byte)0x1C,(byte)0x7F,(byte)0x5E,(byte)0xB1,(byte)0x90,(byte)0xF3,(byte)0xD2,(byte)0x35,(byte)0x14,(byte)0x77 ,(byte)0x56,
(byte)0xEA,(byte)0xCB,(byte)0xA8,(byte)0x89,(byte)0x6E,(byte)0x4F,(byte)0x2C,(byte)0x0D,( byte)0xE2,(byte)0xC3,(byte)0xA0,(byte)0x81,(byte)0x66,(byte)0x47,(byte)0x24,(byte)0x05,
(b yte)0xDB,(byte)0xFA,(byte)0x99,(byte)0xB8,(byte)0x5F,(byte)0x7E,(byte)0x1D,(byte)0x3C,(byte)0xD3,(byte)0xF2,( byte)0x91,(byte)0xB0,(byte)0x57,(byte)0x76,(byte)0x15,(byte)0x34,
(byte)0x4C,(byte)0x6D,(byte)0x0E,(byte) 0x2F,(byte)0xC8,(byte)0xE9,(byte)0x8A,(byte)0xAB,(byte)0x44,(byte)0x65,(byte)0x06,(byte)0x27,(byte)0xC0,(byte) 0xE1,(byte)0x82,(byte)0xA3,
(byte)0x7D,(byte)0x5C,(byte)0x3F,(byte)0x1E,(byte)0xF9,(byte)0xD8,(byte)0xBB, (byte)0x9A,(byte)0x75,(byte)0x54,(byte)0x37,(byte)0x16,(byte)0xF1,(byte)0xD0,(byte)0xB3,(byte)0x92,
(byte )0x2E,(byte)0x0F,(byte)0x6C,(byte)0x4D,(byte)0xAA,(byte)0x8B,(byte)0xE8,(byte)0xC9,(byte)0x26,(byte)0x07,(byte )0x64,(byte)0x45,(byte)0xA2,(byte)0x83,(byte)0xE0,(byte)0xC1,
(byte)0x1F,(byte)0x3E,(byte)0x5D,(byte)0x7C ,(byte)0x9B,(byte)0xBA,(byte)0xD9,(byte)0xF8,(byte)0x17,(byte)0x36,(byte)0x55,(byte)0x74,(byte)0x93,(byte)0xB2 ,(byte)0xD1,(byte)0xF0
};
private static int get_crc16_ccitt(byte[] dat a, int len) {
int a =data[0] & 0x00ff;
int b =data[1] & 0x00ff;
int c =data[2] & 0x00ff;
for(int i=2;i c =((la00[a]& 0x00ff) ^ c);
a =((ha00[a]& 0x00ff) ^ b);
B = C;
IF (i == LEN-1) Break;
c = (Data [i + 1] & 0x00FF);
}
return ((a & 0x00ff) << 8)|(b & 0x00ff) & 0xffff;
}
public static void main(String[] args) throws IOException {
//String test=”e0e00024333539333639303830343735363135000000000018a920190704155205″;
String test=”CBCAFF191C345EBCA89F0000000000E0E00022333539333639303832343439363236FFFFFFFFFF81BB1300000012340000362120190704101912″;
parse Data
Data
int crc16 = half_crc.get_crc16_ccitt(buffer,buffer.length);
System.out.println(Integer.toHexString(crc16));
}
}
< p>
//*************
C# Version:
static byte[] ha00 = {
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1 ,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3, 0x04, 0x04 ,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x66,0x7,0x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CF,0x09,0xAC0x09,0x28,0x28
0x53,0x72,0x11,0x30,0xD7,0xF6,0x95,0xB4,0x5B,0x7A,0x19,0x38,0xDF,0xFE,0x9D,0xBC, 0xFE,0x9D,0xBC, 0x4,0x40,0x40,0x6,0x6,0x6,0x6 0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B,
0xF5,0xD4,0xB7,0x96,0x71,0x50,0x0x96,0x58,0x50,0x0x,0x58,0x12 ,0x3B,0x1A,
0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x49,0x49,0x0B,0x49,0x0B,0x49,0x0B,0x49,0x0B ,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78,
0x88,0xA9,0xCA,0xEB,0x0C,0x2,0x2 0xE3,0x04,0x25,0x46,0x67,
0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x35,0x14,0x35,0x14,0x35 1 ,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB, 1 ,
0x2E, 0x0F, 0x6C, 0x4D, 0xAA, 0x8B, 0xE8, 0xC9, 0x26, 0x07, 0x64, 0x45, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xA2, 0x83, 0xE0, 0xC1, 0xB ,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
} };
private static int get_crc16_cc(byte) private static int get_crc16_cc > {
int a = data[0] & 0x00ff;
int b = data[1] & 0x00ff;
int c = data[2] & 0x00 int i = 2; i {
{
c = ((la00[a] & 0x00ff) ^ c);
00 [ffa] & 0x ;
b = c;
if (i == len-1) break;
c = (data[i + 1] & 0x00ff);
(a & 0x00ff) << 8) | (b & 0x00ff) & 0xffff;
}
//************
C++ Version:
const unsigned char ha00[256] ={
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1, 0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x34 0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xA5 ,0x87,0xF7,0xE7,0xD7,0xC7,
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0x9,0x0xA9,0x ,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,0x3C,0x5C,0x3C,0x5C,0x3C,0x5C 0xED,0xFD,0xCD,0xDD,0xAD,0xBD,0x8D,0x9D,
0x7E,0x6E,0x5E,0x4E,0x3E,0x2E,0x1E,0x0E,0xFF,0xEF,0xDF,0xCF,0x8F,0xBF ,
0x91,0x81,0xB1,0xA1,0xD1,0xC1,0xF1,0xE1,0x10,0x00,0x30,0x20,0x50,0x40,0x70,0x60,
0x83,0x93,0xA3,0xB3,0xC3,0xD3 ,0xE3,0xF3,0x02,0x12,0x22,0x32,0x42,0x52,0x62,0x72,
0xB5,0xA5,0x95,0x85,0xF5,0xE5,0xD5,0xC5,0x34,0x24,0x14,0x14,0x14 0x64,0x54,0x44,
0xA7,0xB7,0x87,0x97,0xE7,0xF7,0xC7,0xD7,0x26,0x36,0x06,0x16,0x66,0x76,0x46,0x56,
0xD9,0xF9, 0xD9,0x 0xE9,0x99,0x89,0xB9,0xA9,0x58,0x48,0x78,0x68,0x18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C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05,
0xDB, 0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44 ,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5 D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
void CRC16_ccitt(unsigned char *a,unsigned char *b,unsigned char *c) { *c = la00[*a] ^ *c; *a = ha00[*a] ^ *b; *b = *c; }
static byte[] ha00 = {
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7,
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9,
0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,0x4C,0x5C,0x2C,0x3C,0x0C,0x1C,0xED,0xFD,0xCD,0xDD,0xAD,0xBD,0x8D,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x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B,
0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0xFD,0xDC,0xBF,0x9E,0x79,0x58,0x3B,0x1A,
0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0x49,
0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78,
0x88,0xA9,0xCA,0xEB,0x0C,0x2D,0x4E,0x6F,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67,
0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56,
0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0 x81,0x66,0x47,0x24,0x05,
0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
private static int get_crc16_ccitt(byte[] data, int len)
{
int a = data[0] & 0x00ff;
int b = data[1] & 0x00ff;
int c = data[2] & 0x00ff;
for (int i = 2; i < len; i++)
{
c = ((la00[a] & 0x00ff) ^ c);
a = ((ha00[a] & 0x00ff) ^ b);
b = c;
if (i == len – 1) break;
c = (data[i + 1] & 0x00ff);
}
return ((a & 0x00ff) << 8) | (b & 0x00ff) & 0xffff;
}
//************
C++ 版:
const unsigned char ha00[256] ={
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7,
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9,
0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,0x4C,0x5C,0x2C,0x3C,0x0C,0x1C,0xED,0xFD,0xCD,0xDD,0xAD,0xBD,0x8D,0x9D,
0x7E,0x6E,0x5E,0x4E,0x3E,0x2E,0x1E,0x0E,0xFF,0xEF,0xDF,0xCF,0xBF,0xAF,0x9F,0x8F,
0x91,0x81,0x B1,0xA1,0xD1,0xC1,0xF1,0xE1,0x10,0x00,0x30,0x20,0x50,0x40,0x70,0x60,
0x83,0x93,0xA3,0xB3,0xC3,0xD3,0xE3,0xF3,0x02,0x12,0x22,0x32,0x42,0x52,0x62,0x72,
0xB5,0xA5,0x95,0x85,0xF5,0xE5,0xD5,0xC5,0x34,0x24,0x14,0x04,0x74,0x64,0x54,0x44,
0xA7,0xB7,0x87,0x97,0xE7,0xF7,0xC7,0xD7,0x26,0x36,0x06,0x16,0x66,0x76,0x46,0x56,
0xD9,0xC9,0xF9,0xE9,0x99,0x89,0xB9,0xA9,0x58,0x48,0x78,0x68,0x18,0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8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05,
0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0x AA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
void CRC16_ccitt(unsigned char *a,unsigned char *b,unsigned char *c) { *c = la00[*a] ^ *c; *a = ha00[*a] ^ *b; *b = *c; }
const unsigned char ha00[256] ={
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7,
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9,
0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,0x4C,0x5C,0x2C,0x3C,0x0C,0x1C,0xED,0xFD,0xCD,0x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0x86,0xA7,0x40,0x61,0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B,
0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0xFD,0xDC,0xBF,0x9E,0x79,0x58,0x3B,0x1A,
0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0x49,
0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78,
0x88,0xA9,0xCA,0xEB,0x0C,0x2D,0x4E,0x6F,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67,
0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56,
0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05,
0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92, 0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
void CRC16_ccitt(unsigned char *a,unsigned char *b,unsigned char *c) { *c = la00[*a] ^ *c; *a = ha00[*a] ^ *b; *b = *c; }