using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CRC.CRC16
{
///
/// CRC16-CCITT x16+x12+x5+1
/// 0x1021
/// ISO HDLC, ITU X.25, V.34/V.41/V.42, PPP-FCS
///
public class CRC16
{
/*
Algorithm Poly Init RefIn RefOut XorOut
CRC-16/CCITT-FALSE 0x1021 0xFFFF false false 0x0000
CRC-16/ARC 0x8005 0x0000 true true 0x0000
CRC-16/AUG-CCITT 0x1021 0x1D0F false false 0x0000
CRC-16/BUYPASS 0x8005 0x0000 false false 0x0000
CRC-16/CDMA2000 0xC867 0xFFFF false false 0x0000
CRC-16/DDS-110 0x8005 0x800D false false 0x0000
CRC-16/DECT-R 0x0589 0x0000 false false 0x0001
CRC-16/DECT-X 0x0589 0x0000 false false 0x0000
CRC-16/DNP 0x3D65 0x0000 true true 0xFFFF
CRC-16/EN-13757 0x3D65 0x0000 false false 0xFFFF
CRC-16/GENIBUS 0x1021 0xFFFF false false 0xFFFF
CRC-16/MAXIM 0x8005 0x0000 true true 0xFFFF
CRC-16/MCRF4XX 0x1021 0xFFFF true true 0x0000
CRC-16/RIELLO 0x1021 0xB2AA true true 0x0000
CRC-16/T10-DIF 0x8BB7 0x0000 false false 0x0000
CRC-16/TELEDISK 0xA097 0x0000 false false 0x0000
CRC-16/TMS37157 0x1021 0x89EC true true 0x0000
CRC-16/USB 0x8005 0xFFFF true true 0xFFFF
CRC-A 0x1021 0xC6C6 true true 0x0000
CRC-16/KERMIT 0x1021 0x0000 true true 0x0000
CRC-16/MODBUS 0x8005 0xFFFF true true 0x0000
CRC-16/X-25 0x1021 0xFFFF true true 0xFFFF
CRC-16/XMODEM 0x1021 0x0000 false false 0x0000
*
*
*/
public struct Scm_CRC16_InputParameters
{
///
/// 算法名称
///
public string AlgorithmName;
///
/// 是否大端模式,
/// 大端模式,高字节在前,左移计算,多项式无需反转
/// 小端模式,低字节在前,右移计算,多项式需反转
///
public bool LittleEndian;
///
/// 多项式
///
public ushort Polynomial;
///
/// crc寄存器宽度
/// 只读
///
public int cWidth { get { return sizeof(UInt16)/sizeof(byte) * 8; } }
///
/// 数据
///
public byte[] Datas;
///
/// 初始crc值
///
public ushort InitCrc;
///
/// 输入反转
///
public bool RefIn;
///
/// 输出反转
///
public bool RefOut;
///
/// 输出是否异或
///
//public bool isOutputXor;
///
/// 输出异或值
///
public ushort XorOut;
}
#region table
readonly UInt16[] Crc16_Poly1021_Table16_Reflect = new UInt16[256]
{
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
};
readonly UInt16[] Crc16_Poly1021_Table16 = new UInt16[256]
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
readonly UInt16[] Crc16_Poly8005_Table16_Reflect = new UInt16[256]
{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
readonly UInt16[] Crc16_Poly8005_Table16 = new UInt16[256]
{
0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022,
0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072,
0x0050, 0x8055, 0x805F, 0x005A, 0x804B, 0x004E, 0x0044, 0x8041,
0x80C3, 0x00C6, 0x00CC, 0x80C9, 0x00D8, 0x80DD, 0x80D7, 0x00D2,
0x00F0, 0x80F5, 0x80FF, 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1,
0x00A0, 0x80A5, 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1,
0x8093, 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082,
0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, 0x0192,
0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, 0x01A4, 0x81A1,
0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, 0x01FE, 0x01F4, 0x81F1,
0x81D3, 0x01D6, 0x01DC, 0x81D9, 0x01C8, 0x81CD, 0x81C7, 0x01C2,
0x0140, 0x8145, 0x814F, 0x014A, 0x815B, 0x015E, 0x0154, 0x8151,
0x8173, 0x0176, 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162,
0x8123, 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132,
0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, 0x8101,
0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, 0x8317, 0x0312,
0x0330, 0x8335, 0x833F, 0x033A, 0x832B, 0x032E, 0x0324, 0x8321,
0x0360, 0x8365, 0x836F, 0x036A, 0x837B, 0x037E, 0x0374, 0x8371,
0x8353, 0x0356, 0x035C, 0x8359, 0x0348, 0x834D, 0x8347, 0x0342,
0x03C0, 0x83C5, 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1,
0x83F3, 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2,
0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, 0x03B2,
0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, 0x0384, 0x8381,
0x0280, 0x8285, 0x828F, 0x028A, 0x829B, 0x029E, 0x0294, 0x8291,
0x82B3, 0x02B6, 0x02BC, 0x82B9, 0x02A8, 0x82AD, 0x82A7, 0x02A2,
0x82E3, 0x02E6, 0x02EC, 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2,
0x02D0, 0x82D5, 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1,
0x8243, 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252,
0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, 0x8261,
0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231,
0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202
};
readonly UInt16[] Crc16_PolyC867_Table16_Reflect = new UInt16[256]
{
0x0000, 0x5A7A, 0xB4F4, 0xEE8E, 0xA5CF, 0xFFB5, 0x113B, 0x4B41,
0x87B9, 0xDDC3, 0x334D, 0x6937, 0x2276, 0x780C, 0x9682, 0xCCF8,
0xC355, 0x992F, 0x77A1, 0x2DDB, 0x669A, 0x3CE0, 0xD26E, 0x8814,
0x44EC, 0x1E96, 0xF018, 0xAA62, 0xE123, 0xBB59, 0x55D7, 0x0FAD,
0x4A8D, 0x10F7, 0xFE79, 0xA403, 0xEF42, 0xB538, 0x5BB6, 0x01CC,
0xCD34, 0x974E, 0x79C0, 0x23BA, 0x68FB, 0x3281, 0xDC0F, 0x8675,
0x89D8, 0xD3A2, 0x3D2C, 0x6756, 0x2C17, 0x766D, 0x98E3, 0xC299,
0x0E61, 0x541B, 0xBA95, 0xE0EF, 0xABAE, 0xF1D4, 0x1F5A, 0x4520,
0x951A, 0xCF60, 0x21EE, 0x7B94, 0x30D5, 0x6AAF, 0x8421, 0xDE5B,
0x12A3, 0x48D9, 0xA657, 0xFC2D, 0xB76C, 0xED16, 0x0398, 0x59E2,
0x564F, 0x0C35, 0xE2BB, 0xB8C1, 0xF380, 0xA9FA, 0x4774, 0x1D0E,
0xD1F6, 0x8B8C, 0x6502, 0x3F78, 0x7439, 0x2E43, 0xC0CD, 0x9AB7,
0xDF97, 0x85ED, 0x6B63, 0x3119, 0x7A58, 0x2022, 0xCEAC, 0x94D6,
0x582E, 0x0254, 0xECDA, 0xB6A0, 0xFDE1, 0xA79B, 0x4915, 0x136F,
0x1CC2, 0x46B8, 0xA836, 0xF24C, 0xB90D, 0xE377, 0x0DF9, 0x5783,
0x9B7B, 0xC101, 0x2F8F, 0x75F5, 0x3EB4, 0x64CE, 0x8A40, 0xD03A,
0xE613, 0xBC69, 0x52E7, 0x089D, 0x43DC, 0x19A6, 0xF728, 0xAD52,
0x61AA, 0x3BD0, 0xD55E, 0x8F24, 0xC465, 0x9E1F, 0x7091, 0x2AEB,
0x2546, 0x7F3C, 0x91B2, 0xCBC8, 0x8089, 0xDAF3, 0x347D, 0x6E07,
0xA2FF, 0xF885, 0x160B, 0x4C71, 0x0730, 0x5D4A, 0xB3C4, 0xE9BE,
0xAC9E, 0xF6E4, 0x186A, 0x4210, 0x0951, 0x532B, 0xBDA5, 0xE7DF,
0x2B27, 0x715D, 0x9FD3, 0xC5A9, 0x8EE8, 0xD492, 0x3A1C, 0x6066,
0x6FCB, 0x35B1, 0xDB3F, 0x8145, 0xCA04, 0x907E, 0x7EF0, 0x248A,
0xE872, 0xB208, 0x5C86, 0x06FC, 0x4DBD, 0x17C7, 0xF949, 0xA333,
0x7309, 0x2973, 0xC7FD, 0x9D87, 0xD6C6, 0x8CBC, 0x6232, 0x3848,
0xF4B0, 0xAECA, 0x4044, 0x1A3E, 0x517F, 0x0B05, 0xE58B, 0xBFF1,
0xB05C, 0xEA26, 0x04A8, 0x5ED2, 0x1593, 0x4FE9, 0xA167, 0xFB1D,
0x37E5, 0x6D9F, 0x8311, 0xD96B, 0x922A, 0xC850, 0x26DE, 0x7CA4,
0x3984, 0x63FE, 0x8D70, 0xD70A, 0x9C4B, 0xC631, 0x28BF, 0x72C5,
0xBE3D, 0xE447, 0x0AC9, 0x50B3, 0x1BF2, 0x4188, 0xAF06, 0xF57C,
0xFAD1, 0xA0AB, 0x4E25, 0x145F, 0x5F1E, 0x0564, 0xEBEA, 0xB190,
0x7D68, 0x2712, 0xC99C, 0x93E6, 0xD8A7, 0x82DD, 0x6C53, 0x3629
};
readonly UInt16[] Crc16_PolyC867_Table16 = new UInt16[256]
{
0x0000, 0xC867, 0x58A9, 0x90CE, 0xB152, 0x7935, 0xE9FB, 0x219C,
0xAAC3, 0x62A4, 0xF26A, 0x3A0D, 0x1B91, 0xD3F6, 0x4338, 0x8B5F,
0x9DE1, 0x5586, 0xC548, 0x0D2F, 0x2CB3, 0xE4D4, 0x741A, 0xBC7D,
0x3722, 0xFF45, 0x6F8B, 0xA7EC, 0x8670, 0x4E17, 0xDED9, 0x16BE,
0xF3A5, 0x3BC2, 0xAB0C, 0x636B, 0x42F7, 0x8A90, 0x1A5E, 0xD239,
0x5966, 0x9101, 0x01CF, 0xC9A8, 0xE834, 0x2053, 0xB09D, 0x78FA,
0x6E44, 0xA623, 0x36ED, 0xFE8A, 0xDF16, 0x1771, 0x87BF, 0x4FD8,
0xC487, 0x0CE0, 0x9C2E, 0x5449, 0x75D5, 0xBDB2, 0x2D7C, 0xE51B,
0x2F2D, 0xE74A, 0x7784, 0xBFE3, 0x9E7F, 0x5618, 0xC6D6, 0x0EB1,
0x85EE, 0x4D89, 0xDD47, 0x1520, 0x34BC, 0xFCDB, 0x6C15, 0xA472,
0xB2CC, 0x7AAB, 0xEA65, 0x2202, 0x039E, 0xCBF9, 0x5B37, 0x9350,
0x180F, 0xD068, 0x40A6, 0x88C1, 0xA95D, 0x613A, 0xF1F4, 0x3993,
0xDC88, 0x14EF, 0x8421, 0x4C46, 0x6DDA, 0xA5BD, 0x3573, 0xFD14,
0x764B, 0xBE2C, 0x2EE2, 0xE685, 0xC719, 0x0F7E, 0x9FB0, 0x57D7,
0x4169, 0x890E, 0x19C0, 0xD1A7, 0xF03B, 0x385C, 0xA892, 0x60F5,
0xEBAA, 0x23CD, 0xB303, 0x7B64, 0x5AF8, 0x929F, 0x0251, 0xCA36,
0x5E5A, 0x963D, 0x06F3, 0xCE94, 0xEF08, 0x276F, 0xB7A1, 0x7FC6,
0xF499, 0x3CFE, 0xAC30, 0x6457, 0x45CB, 0x8DAC, 0x1D62, 0xD505,
0xC3BB, 0x0BDC, 0x9B12, 0x5375, 0x72E9, 0xBA8E, 0x2A40, 0xE227,
0x6978, 0xA11F, 0x31D1, 0xF9B6, 0xD82A, 0x104D, 0x8083, 0x48E4,
0xADFF, 0x6598, 0xF556, 0x3D31, 0x1CAD, 0xD4CA, 0x4404, 0x8C63,
0x073C, 0xCF5B, 0x5F95, 0x97F2, 0xB66E, 0x7E09, 0xEEC7, 0x26A0,
0x301E, 0xF879, 0x68B7, 0xA0D0, 0x814C, 0x492B, 0xD9E5, 0x1182,
0x9ADD, 0x52BA, 0xC274, 0x0A13, 0x2B8F, 0xE3E8, 0x7326, 0xBB41,
0x7177, 0xB910, 0x29DE, 0xE1B9, 0xC025, 0x0842, 0x988C, 0x50EB,
0xDBB4, 0x13D3, 0x831D, 0x4B7A, 0x6AE6, 0xA281, 0x324F, 0xFA28,
0xEC96, 0x24F1, 0xB43F, 0x7C58, 0x5DC4, 0x95A3, 0x056D, 0xCD0A,
0x4655, 0x8E32, 0x1EFC, 0xD69B, 0xF707, 0x3F60, 0xAFAE, 0x67C9,
0x82D2, 0x4AB5, 0xDA7B, 0x121C, 0x3380, 0xFBE7, 0x6B29, 0xA34E,
0x2811, 0xE076, 0x70B8, 0xB8DF, 0x9943, 0x5124, 0xC1EA, 0x098D,
0x1F33, 0xD754, 0x479A, 0x8FFD, 0xAE61, 0x6606, 0xF6C8, 0x3EAF,
0xB5F0, 0x7D97, 0xED59, 0x253E, 0x04A2, 0xCCC5, 0x5C0B, 0x946C
};
readonly UInt16[] Crc16_Poly0589_Table16_Reflect = new UInt16[256]
{
0x0000, 0x49F3, 0x93E6, 0xDA15, 0x048D, 0x4D7E, 0x976B, 0xDE98,
0x091A, 0x40E9, 0x9AFC, 0xD30F, 0x0D97, 0x4464, 0x9E71, 0xD782,
0x1234, 0x5BC7, 0x81D2, 0xC821, 0x16B9, 0x5F4A, 0x855F, 0xCCAC,
0x1B2E, 0x52DD, 0x88C8, 0xC13B, 0x1FA3, 0x5650, 0x8C45, 0xC5B6,
0x2468, 0x6D9B, 0xB78E, 0xFE7D, 0x20E5, 0x6916, 0xB303, 0xFAF0,
0x2D72, 0x6481, 0xBE94, 0xF767, 0x29FF, 0x600C, 0xBA19, 0xF3EA,
0x365C, 0x7FAF, 0xA5BA, 0xEC49, 0x32D1, 0x7B22, 0xA137, 0xE8C4,
0x3F46, 0x76B5, 0xACA0, 0xE553, 0x3BCB, 0x7238, 0xA82D, 0xE1DE,
0x48D0, 0x0123, 0xDB36, 0x92C5, 0x4C5D, 0x05AE, 0xDFBB, 0x9648,
0x41CA, 0x0839, 0xD22C, 0x9BDF, 0x4547, 0x0CB4, 0xD6A1, 0x9F52,
0x5AE4, 0x1317, 0xC902, 0x80F1, 0x5E69, 0x179A, 0xCD8F, 0x847C,
0x53FE, 0x1A0D, 0xC018, 0x89EB, 0x5773, 0x1E80, 0xC495, 0x8D66,
0x6CB8, 0x254B, 0xFF5E, 0xB6AD, 0x6835, 0x21C6, 0xFBD3, 0xB220,
0x65A2, 0x2C51, 0xF644, 0xBFB7, 0x612F, 0x28DC, 0xF2C9, 0xBB3A,
0x7E8C, 0x377F, 0xED6A, 0xA499, 0x7A01, 0x33F2, 0xE9E7, 0xA014,
0x7796, 0x3E65, 0xE470, 0xAD83, 0x731B, 0x3AE8, 0xE0FD, 0xA90E,
0x91A0, 0xD853, 0x0246, 0x4BB5, 0x952D, 0xDCDE, 0x06CB, 0x4F38,
0x98BA, 0xD149, 0x0B5C, 0x42AF, 0x9C37, 0xD5C4, 0x0FD1, 0x4622,
0x8394, 0xCA67, 0x1072, 0x5981, 0x8719, 0xCEEA, 0x14FF, 0x5D0C,
0x8A8E, 0xC37D, 0x1968, 0x509B, 0x8E03, 0xC7F0, 0x1DE5, 0x5416,
0xB5C8, 0xFC3B, 0x262E, 0x6FDD, 0xB145, 0xF8B6, 0x22A3, 0x6B50,
0xBCD2, 0xF521, 0x2F34, 0x66C7, 0xB85F, 0xF1AC, 0x2BB9, 0x624A,
0xA7FC, 0xEE0F, 0x341A, 0x7DE9, 0xA371, 0xEA82, 0x3097, 0x7964,
0xAEE6, 0xE715, 0x3D00, 0x74F3, 0xAA6B, 0xE398, 0x398D, 0x707E,
0xD970, 0x9083, 0x4A96, 0x0365, 0xDDFD, 0x940E, 0x4E1B, 0x07E8,
0xD06A, 0x9999, 0x438C, 0x0A7F, 0xD4E7, 0x9D14, 0x4701, 0x0EF2,
0xCB44, 0x82B7, 0x58A2, 0x1151, 0xCFC9, 0x863A, 0x5C2F, 0x15DC,
0xC25E, 0x8BAD, 0x51B8, 0x184B, 0xC6D3, 0x8F20, 0x5535, 0x1CC6,
0xFD18, 0xB4EB, 0x6EFE, 0x270D, 0xF995, 0xB066, 0x6A73, 0x2380,
0xF402, 0xBDF1, 0x67E4, 0x2E17, 0xF08F, 0xB97C, 0x6369, 0x2A9A,
0xEF2C, 0xA6DF, 0x7CCA, 0x3539, 0xEBA1, 0xA252, 0x7847, 0x31B4,
0xE636, 0xAFC5, 0x75D0, 0x3C23, 0xE2BB, 0xAB48, 0x715D, 0x38AE
};
readonly UInt16[] Crc16_Poly0589_Table16 = new UInt16[256]
{
0x0000, 0x0589, 0x0B12, 0x0E9B, 0x1624, 0x13AD, 0x1D36, 0x18BF,
0x2C48, 0x29C1, 0x275A, 0x22D3, 0x3A6C, 0x3FE5, 0x317E, 0x34F7,
0x5890, 0x5D19, 0x5382, 0x560B, 0x4EB4, 0x4B3D, 0x45A6, 0x402F,
0x74D8, 0x7151, 0x7FCA, 0x7A43, 0x62FC, 0x6775, 0x69EE, 0x6C67,
0xB120, 0xB4A9, 0xBA32, 0xBFBB, 0xA704, 0xA28D, 0xAC16, 0xA99F,
0x9D68, 0x98E1, 0x967A, 0x93F3, 0x8B4C, 0x8EC5, 0x805E, 0x85D7,
0xE9B0, 0xEC39, 0xE2A2, 0xE72B, 0xFF94, 0xFA1D, 0xF486, 0xF10F,
0xC5F8, 0xC071, 0xCEEA, 0xCB63, 0xD3DC, 0xD655, 0xD8CE, 0xDD47,
0x67C9, 0x6240, 0x6CDB, 0x6952, 0x71ED, 0x7464, 0x7AFF, 0x7F76,
0x4B81, 0x4E08, 0x4093, 0x451A, 0x5DA5, 0x582C, 0x56B7, 0x533E,
0x3F59, 0x3AD0, 0x344B, 0x31C2, 0x297D, 0x2CF4, 0x226F, 0x27E6,
0x1311, 0x1698, 0x1803, 0x1D8A, 0x0535, 0x00BC, 0x0E27, 0x0BAE,
0xD6E9, 0xD360, 0xDDFB, 0xD872, 0xC0CD, 0xC544, 0xCBDF, 0xCE56,
0xFAA1, 0xFF28, 0xF1B3, 0xF43A, 0xEC85, 0xE90C, 0xE797, 0xE21E,
0x8E79, 0x8BF0, 0x856B, 0x80E2, 0x985D, 0x9DD4, 0x934F, 0x96C6,
0xA231, 0xA7B8, 0xA923, 0xACAA, 0xB415, 0xB19C, 0xBF07, 0xBA8E,
0xCF92, 0xCA1B, 0xC480, 0xC109, 0xD9B6, 0xDC3F, 0xD2A4, 0xD72D,
0xE3DA, 0xE653, 0xE8C8, 0xED41, 0xF5FE, 0xF077, 0xFEEC, 0xFB65,
0x9702, 0x928B, 0x9C10, 0x9999, 0x8126, 0x84AF, 0x8A34, 0x8FBD,
0xBB4A, 0xBEC3, 0xB058, 0xB5D1, 0xAD6E, 0xA8E7, 0xA67C, 0xA3F5,
0x7EB2, 0x7B3B, 0x75A0, 0x7029, 0x6896, 0x6D1F, 0x6384, 0x660D,
0x52FA, 0x5773, 0x59E8, 0x5C61, 0x44DE, 0x4157, 0x4FCC, 0x4A45,
0x2622, 0x23AB, 0x2D30, 0x28B9, 0x3006, 0x358F, 0x3B14, 0x3E9D,
0x0A6A, 0x0FE3, 0x0178, 0x04F1, 0x1C4E, 0x19C7, 0x175C, 0x12D5,
0xA85B, 0xADD2, 0xA349, 0xA6C0, 0xBE7F, 0xBBF6, 0xB56D, 0xB0E4,
0x8413, 0x819A, 0x8F01, 0x8A88, 0x9237, 0x97BE, 0x9925, 0x9CAC,
0xF0CB, 0xF542, 0xFBD9, 0xFE50, 0xE6EF, 0xE366, 0xEDFD, 0xE874,
0xDC83, 0xD90A, 0xD791, 0xD218, 0xCAA7, 0xCF2E, 0xC1B5, 0xC43C,
0x197B, 0x1CF2, 0x1269, 0x17E0, 0x0F5F, 0x0AD6, 0x044D, 0x01C4,
0x3533, 0x30BA, 0x3E21, 0x3BA8, 0x2317, 0x269E, 0x2805, 0x2D8C,
0x41EB, 0x4462, 0x4AF9, 0x4F70, 0x57CF, 0x5246, 0x5CDD, 0x5954,
0x6DA3, 0x682A, 0x66B1, 0x6338, 0x7B87, 0x7E0E, 0x7095, 0x751C
};
readonly UInt16[] Crc16_Poly3D65_Table16_Reflect = new UInt16[256]
{
0x0000, 0x365E, 0x6CBC, 0x5AE2, 0xD978, 0xEF26, 0xB5C4, 0x839A,
0xFF89, 0xC9D7, 0x9335, 0xA56B, 0x26F1, 0x10AF, 0x4A4D, 0x7C13,
0xB26B, 0x8435, 0xDED7, 0xE889, 0x6B13, 0x5D4D, 0x07AF, 0x31F1,
0x4DE2, 0x7BBC, 0x215E, 0x1700, 0x949A, 0xA2C4, 0xF826, 0xCE78,
0x29AF, 0x1FF1, 0x4513, 0x734D, 0xF0D7, 0xC689, 0x9C6B, 0xAA35,
0xD626, 0xE078, 0xBA9A, 0x8CC4, 0x0F5E, 0x3900, 0x63E2, 0x55BC,
0x9BC4, 0xAD9A, 0xF778, 0xC126, 0x42BC, 0x74E2, 0x2E00, 0x185E,
0x644D, 0x5213, 0x08F1, 0x3EAF, 0xBD35, 0x8B6B, 0xD189, 0xE7D7,
0x535E, 0x6500, 0x3FE2, 0x09BC, 0x8A26, 0xBC78, 0xE69A, 0xD0C4,
0xACD7, 0x9A89, 0xC06B, 0xF635, 0x75AF, 0x43F1, 0x1913, 0x2F4D,
0xE135, 0xD76B, 0x8D89, 0xBBD7, 0x384D, 0x0E13, 0x54F1, 0x62AF,
0x1EBC, 0x28E2, 0x7200, 0x445E, 0xC7C4, 0xF19A, 0xAB78, 0x9D26,
0x7AF1, 0x4CAF, 0x164D, 0x2013, 0xA389, 0x95D7, 0xCF35, 0xF96B,
0x8578, 0xB326, 0xE9C4, 0xDF9A, 0x5C00, 0x6A5E, 0x30BC, 0x06E2,
0xC89A, 0xFEC4, 0xA426, 0x9278, 0x11E2, 0x27BC, 0x7D5E, 0x4B00,
0x3713, 0x014D, 0x5BAF, 0x6DF1, 0xEE6B, 0xD835, 0x82D7, 0xB489,
0xA6BC, 0x90E2, 0xCA00, 0xFC5E, 0x7FC4, 0x499A, 0x1378, 0x2526,
0x5935, 0x6F6B, 0x3589, 0x03D7, 0x804D, 0xB613, 0xECF1, 0xDAAF,
0x14D7, 0x2289, 0x786B, 0x4E35, 0xCDAF, 0xFBF1, 0xA113, 0x974D,
0xEB5E, 0xDD00, 0x87E2, 0xB1BC, 0x3226, 0x0478, 0x5E9A, 0x68C4,
0x8F13, 0xB94D, 0xE3AF, 0xD5F1, 0x566B, 0x6035, 0x3AD7, 0x0C89,
0x709A, 0x46C4, 0x1C26, 0x2A78, 0xA9E2, 0x9FBC, 0xC55E, 0xF300,
0x3D78, 0x0B26, 0x51C4, 0x679A, 0xE400, 0xD25E, 0x88BC, 0xBEE2,
0xC2F1, 0xF4AF, 0xAE4D, 0x9813, 0x1B89, 0x2DD7, 0x7735, 0x416B,
0xF5E2, 0xC3BC, 0x995E, 0xAF00, 0x2C9A, 0x1AC4, 0x4026, 0x7678,
0x0A6B, 0x3C35, 0x66D7, 0x5089, 0xD313, 0xE54D, 0xBFAF, 0x89F1,
0x4789, 0x71D7, 0x2B35, 0x1D6B, 0x9EF1, 0xA8AF, 0xF24D, 0xC413,
0xB800, 0x8E5E, 0xD4BC, 0xE2E2, 0x6178, 0x5726, 0x0DC4, 0x3B9A,
0xDC4D, 0xEA13, 0xB0F1, 0x86AF, 0x0535, 0x336B, 0x6989, 0x5FD7,
0x23C4, 0x159A, 0x4F78, 0x7926, 0xFABC, 0xCCE2, 0x9600, 0xA05E,
0x6E26, 0x5878, 0x029A, 0x34C4, 0xB75E, 0x8100, 0xDBE2, 0xEDBC,
0x91AF, 0xA7F1, 0xFD13, 0xCB4D, 0x48D7, 0x7E89, 0x246B, 0x1235
};
readonly UInt16[] Crc16_Poly3D65_Table16 = new UInt16[256]
{
0x0000, 0x3D65, 0x7ACA, 0x47AF, 0xF594, 0xC8F1, 0x8F5E, 0xB23B,
0xD64D, 0xEB28, 0xAC87, 0x91E2, 0x23D9, 0x1EBC, 0x5913, 0x6476,
0x91FF, 0xAC9A, 0xEB35, 0xD650, 0x646B, 0x590E, 0x1EA1, 0x23C4,
0x47B2, 0x7AD7, 0x3D78, 0x001D, 0xB226, 0x8F43, 0xC8EC, 0xF589,
0x1E9B, 0x23FE, 0x6451, 0x5934, 0xEB0F, 0xD66A, 0x91C5, 0xACA0,
0xC8D6, 0xF5B3, 0xB21C, 0x8F79, 0x3D42, 0x0027, 0x4788, 0x7AED,
0x8F64, 0xB201, 0xF5AE, 0xC8CB, 0x7AF0, 0x4795, 0x003A, 0x3D5F,
0x5929, 0x644C, 0x23E3, 0x1E86, 0xACBD, 0x91D8, 0xD677, 0xEB12,
0x3D36, 0x0053, 0x47FC, 0x7A99, 0xC8A2, 0xF5C7, 0xB268, 0x8F0D,
0xEB7B, 0xD61E, 0x91B1, 0xACD4, 0x1EEF, 0x238A, 0x6425, 0x5940,
0xACC9, 0x91AC, 0xD603, 0xEB66, 0x595D, 0x6438, 0x2397, 0x1EF2,
0x7A84, 0x47E1, 0x004E, 0x3D2B, 0x8F10, 0xB275, 0xF5DA, 0xC8BF,
0x23AD, 0x1EC8, 0x5967, 0x6402, 0xD639, 0xEB5C, 0xACF3, 0x9196,
0xF5E0, 0xC885, 0x8F2A, 0xB24F, 0x0074, 0x3D11, 0x7ABE, 0x47DB,
0xB252, 0x8F37, 0xC898, 0xF5FD, 0x47C6, 0x7AA3, 0x3D0C, 0x0069,
0x641F, 0x597A, 0x1ED5, 0x23B0, 0x918B, 0xACEE, 0xEB41, 0xD624,
0x7A6C, 0x4709, 0x00A6, 0x3DC3, 0x8FF8, 0xB29D, 0xF532, 0xC857,
0xAC21, 0x9144, 0xD6EB, 0xEB8E, 0x59B5, 0x64D0, 0x237F, 0x1E1A,
0xEB93, 0xD6F6, 0x9159, 0xAC3C, 0x1E07, 0x2362, 0x64CD, 0x59A8,
0x3DDE, 0x00BB, 0x4714, 0x7A71, 0xC84A, 0xF52F, 0xB280, 0x8FE5,
0x64F7, 0x5992, 0x1E3D, 0x2358, 0x9163, 0xAC06, 0xEBA9, 0xD6CC,
0xB2BA, 0x8FDF, 0xC870, 0xF515, 0x472E, 0x7A4B, 0x3DE4, 0x0081,
0xF508, 0xC86D, 0x8FC2, 0xB2A7, 0x009C, 0x3DF9, 0x7A56, 0x4733,
0x2345, 0x1E20, 0x598F, 0x64EA, 0xD6D1, 0xEBB4, 0xAC1B, 0x917E,
0x475A, 0x7A3F, 0x3D90, 0x00F5, 0xB2CE, 0x8FAB, 0xC804, 0xF561,
0x9117, 0xAC72, 0xEBDD, 0xD6B8, 0x6483, 0x59E6, 0x1E49, 0x232C,
0xD6A5, 0xEBC0, 0xAC6F, 0x910A, 0x2331, 0x1E54, 0x59FB, 0x649E,
0x00E8, 0x3D8D, 0x7A22, 0x4747, 0xF57C, 0xC819, 0x8FB6, 0xB2D3,
0x59C1, 0x64A4, 0x230B, 0x1E6E, 0xAC55, 0x9130, 0xD69F, 0xEBFA,
0x8F8C, 0xB2E9, 0xF546, 0xC823, 0x7A18, 0x477D, 0x00D2, 0x3DB7,
0xC83E, 0xF55B, 0xB2F4, 0x8F91, 0x3DAA, 0x00CF, 0x4760, 0x7A05,
0x1E73, 0x2316, 0x64B9, 0x59DC, 0xEBE7, 0xD682, 0x912D, 0xAC48
};
readonly UInt16[] Crc16_Poly8BB7_Table16_Reflect = new UInt16[256]
{
0x0000, 0x8D5C, 0xC11B, 0x4C47, 0x5995, 0xD4C9, 0x988E, 0x15D2,
0xB32A, 0x3E76, 0x7231, 0xFF6D, 0xEABF, 0x67E3, 0x2BA4, 0xA6F8,
0xBDF7, 0x30AB, 0x7CEC, 0xF1B0, 0xE462, 0x693E, 0x2579, 0xA825,
0x0EDD, 0x8381, 0xCFC6, 0x429A, 0x5748, 0xDA14, 0x9653, 0x1B0F,
0xA04D, 0x2D11, 0x6156, 0xEC0A, 0xF9D8, 0x7484, 0x38C3, 0xB59F,
0x1367, 0x9E3B, 0xD27C, 0x5F20, 0x4AF2, 0xC7AE, 0x8BE9, 0x06B5,
0x1DBA, 0x90E6, 0xDCA1, 0x51FD, 0x442F, 0xC973, 0x8534, 0x0868,
0xAE90, 0x23CC, 0x6F8B, 0xE2D7, 0xF705, 0x7A59, 0x361E, 0xBB42,
0x9B39, 0x1665, 0x5A22, 0xD77E, 0xC2AC, 0x4FF0, 0x03B7, 0x8EEB,
0x2813, 0xA54F, 0xE908, 0x6454, 0x7186, 0xFCDA, 0xB09D, 0x3DC1,
0x26CE, 0xAB92, 0xE7D5, 0x6A89, 0x7F5B, 0xF207, 0xBE40, 0x331C,
0x95E4, 0x18B8, 0x54FF, 0xD9A3, 0xCC71, 0x412D, 0x0D6A, 0x8036,
0x3B74, 0xB628, 0xFA6F, 0x7733, 0x62E1, 0xEFBD, 0xA3FA, 0x2EA6,
0x885E, 0x0502, 0x4945, 0xC419, 0xD1CB, 0x5C97, 0x10D0, 0x9D8C,
0x8683, 0x0BDF, 0x4798, 0xCAC4, 0xDF16, 0x524A, 0x1E0D, 0x9351,
0x35A9, 0xB8F5, 0xF4B2, 0x79EE, 0x6C3C, 0xE160, 0xAD27, 0x207B,
0xEDD1, 0x608D, 0x2CCA, 0xA196, 0xB444, 0x3918, 0x755F, 0xF803,
0x5EFB, 0xD3A7, 0x9FE0, 0x12BC, 0x076E, 0x8A32, 0xC675, 0x4B29,
0x5026, 0xDD7A, 0x913D, 0x1C61, 0x09B3, 0x84EF, 0xC8A8, 0x45F4,
0xE30C, 0x6E50, 0x2217, 0xAF4B, 0xBA99, 0x37C5, 0x7B82, 0xF6DE,
0x4D9C, 0xC0C0, 0x8C87, 0x01DB, 0x1409, 0x9955, 0xD512, 0x584E,
0xFEB6, 0x73EA, 0x3FAD, 0xB2F1, 0xA723, 0x2A7F, 0x6638, 0xEB64,
0xF06B, 0x7D37, 0x3170, 0xBC2C, 0xA9FE, 0x24A2, 0x68E5, 0xE5B9,
0x4341, 0xCE1D, 0x825A, 0x0F06, 0x1AD4, 0x9788, 0xDBCF, 0x5693,
0x76E8, 0xFBB4, 0xB7F3, 0x3AAF, 0x2F7D, 0xA221, 0xEE66, 0x633A,
0xC5C2, 0x489E, 0x04D9, 0x8985, 0x9C57, 0x110B, 0x5D4C, 0xD010,
0xCB1F, 0x4643, 0x0A04, 0x8758, 0x928A, 0x1FD6, 0x5391, 0xDECD,
0x7835, 0xF569, 0xB92E, 0x3472, 0x21A0, 0xACFC, 0xE0BB, 0x6DE7,
0xD6A5, 0x5BF9, 0x17BE, 0x9AE2, 0x8F30, 0x026C, 0x4E2B, 0xC377,
0x658F, 0xE8D3, 0xA494, 0x29C8, 0x3C1A, 0xB146, 0xFD01, 0x705D,
0x6B52, 0xE60E, 0xAA49, 0x2715, 0x32C7, 0xBF9B, 0xF3DC, 0x7E80,
0xD878, 0x5524, 0x1963, 0x943F, 0x81ED, 0x0CB1, 0x40F6, 0xCDAA
};
readonly UInt16[] Crc16_Poly8BB7_Table16 = new UInt16[256]
{
0x0000, 0x8BB7, 0x9CD9, 0x176E, 0xB205, 0x39B2, 0x2EDC, 0xA56B,
0xEFBD, 0x640A, 0x7364, 0xF8D3, 0x5DB8, 0xD60F, 0xC161, 0x4AD6,
0x54CD, 0xDF7A, 0xC814, 0x43A3, 0xE6C8, 0x6D7F, 0x7A11, 0xF1A6,
0xBB70, 0x30C7, 0x27A9, 0xAC1E, 0x0975, 0x82C2, 0x95AC, 0x1E1B,
0xA99A, 0x222D, 0x3543, 0xBEF4, 0x1B9F, 0x9028, 0x8746, 0x0CF1,
0x4627, 0xCD90, 0xDAFE, 0x5149, 0xF422, 0x7F95, 0x68FB, 0xE34C,
0xFD57, 0x76E0, 0x618E, 0xEA39, 0x4F52, 0xC4E5, 0xD38B, 0x583C,
0x12EA, 0x995D, 0x8E33, 0x0584, 0xA0EF, 0x2B58, 0x3C36, 0xB781,
0xD883, 0x5334, 0x445A, 0xCFED, 0x6A86, 0xE131, 0xF65F, 0x7DE8,
0x373E, 0xBC89, 0xABE7, 0x2050, 0x853B, 0x0E8C, 0x19E2, 0x9255,
0x8C4E, 0x07F9, 0x1097, 0x9B20, 0x3E4B, 0xB5FC, 0xA292, 0x2925,
0x63F3, 0xE844, 0xFF2A, 0x749D, 0xD1F6, 0x5A41, 0x4D2F, 0xC698,
0x7119, 0xFAAE, 0xEDC0, 0x6677, 0xC31C, 0x48AB, 0x5FC5, 0xD472,
0x9EA4, 0x1513, 0x027D, 0x89CA, 0x2CA1, 0xA716, 0xB078, 0x3BCF,
0x25D4, 0xAE63, 0xB90D, 0x32BA, 0x97D1, 0x1C66, 0x0B08, 0x80BF,
0xCA69, 0x41DE, 0x56B0, 0xDD07, 0x786C, 0xF3DB, 0xE4B5, 0x6F02,
0x3AB1, 0xB106, 0xA668, 0x2DDF, 0x88B4, 0x0303, 0x146D, 0x9FDA,
0xD50C, 0x5EBB, 0x49D5, 0xC262, 0x6709, 0xECBE, 0xFBD0, 0x7067,
0x6E7C, 0xE5CB, 0xF2A5, 0x7912, 0xDC79, 0x57CE, 0x40A0, 0xCB17,
0x81C1, 0x0A76, 0x1D18, 0x96AF, 0x33C4, 0xB873, 0xAF1D, 0x24AA,
0x932B, 0x189C, 0x0FF2, 0x8445, 0x212E, 0xAA99, 0xBDF7, 0x3640,
0x7C96, 0xF721, 0xE04F, 0x6BF8, 0xCE93, 0x4524, 0x524A, 0xD9FD,
0xC7E6, 0x4C51, 0x5B3F, 0xD088, 0x75E3, 0xFE54, 0xE93A, 0x628D,
0x285B, 0xA3EC, 0xB482, 0x3F35, 0x9A5E, 0x11E9, 0x0687, 0x8D30,
0xE232, 0x6985, 0x7EEB, 0xF55C, 0x5037, 0xDB80, 0xCCEE, 0x4759,
0x0D8F, 0x8638, 0x9156, 0x1AE1, 0xBF8A, 0x343D, 0x2353, 0xA8E4,
0xB6FF, 0x3D48, 0x2A26, 0xA191, 0x04FA, 0x8F4D, 0x9823, 0x1394,
0x5942, 0xD2F5, 0xC59B, 0x4E2C, 0xEB47, 0x60F0, 0x779E, 0xFC29,
0x4BA8, 0xC01F, 0xD771, 0x5CC6, 0xF9AD, 0x721A, 0x6574, 0xEEC3,
0xA415, 0x2FA2, 0x38CC, 0xB37B, 0x1610, 0x9DA7, 0x8AC9, 0x017E,
0x1F65, 0x94D2, 0x83BC, 0x080B, 0xAD60, 0x26D7, 0x31B9, 0xBA0E,
0xF0D8, 0x7B6F, 0x6C01, 0xE7B6, 0x42DD, 0xC96A, 0xDE04, 0x55B3
};
readonly UInt16[] Crc16_PolyA097_Table16_Reflect = new UInt16[256]
{
0x0000, 0xF11B, 0x303D, 0xC126, 0x607A, 0x9161, 0x5047, 0xA15C,
0xC0F4, 0x31EF, 0xF0C9, 0x01D2, 0xA08E, 0x5195, 0x90B3, 0x61A8,
0x53E3, 0xA2F8, 0x63DE, 0x92C5, 0x3399, 0xC282, 0x03A4, 0xF2BF,
0x9317, 0x620C, 0xA32A, 0x5231, 0xF36D, 0x0276, 0xC350, 0x324B,
0xA7C6, 0x56DD, 0x97FB, 0x66E0, 0xC7BC, 0x36A7, 0xF781, 0x069A,
0x6732, 0x9629, 0x570F, 0xA614, 0x0748, 0xF653, 0x3775, 0xC66E,
0xF425, 0x053E, 0xC418, 0x3503, 0x945F, 0x6544, 0xA462, 0x5579,
0x34D1, 0xC5CA, 0x04EC, 0xF5F7, 0x54AB, 0xA5B0, 0x6496, 0x958D,
0x9D87, 0x6C9C, 0xADBA, 0x5CA1, 0xFDFD, 0x0CE6, 0xCDC0, 0x3CDB,
0x5D73, 0xAC68, 0x6D4E, 0x9C55, 0x3D09, 0xCC12, 0x0D34, 0xFC2F,
0xCE64, 0x3F7F, 0xFE59, 0x0F42, 0xAE1E, 0x5F05, 0x9E23, 0x6F38,
0x0E90, 0xFF8B, 0x3EAD, 0xCFB6, 0x6EEA, 0x9FF1, 0x5ED7, 0xAFCC,
0x3A41, 0xCB5A, 0x0A7C, 0xFB67, 0x5A3B, 0xAB20, 0x6A06, 0x9B1D,
0xFAB5, 0x0BAE, 0xCA88, 0x3B93, 0x9ACF, 0x6BD4, 0xAAF2, 0x5BE9,
0x69A2, 0x98B9, 0x599F, 0xA884, 0x09D8, 0xF8C3, 0x39E5, 0xC8FE,
0xA956, 0x584D, 0x996B, 0x6870, 0xC92C, 0x3837, 0xF911, 0x080A,
0xE905, 0x181E, 0xD938, 0x2823, 0x897F, 0x7864, 0xB942, 0x4859,
0x29F1, 0xD8EA, 0x19CC, 0xE8D7, 0x498B, 0xB890, 0x79B6, 0x88AD,
0xBAE6, 0x4BFD, 0x8ADB, 0x7BC0, 0xDA9C, 0x2B87, 0xEAA1, 0x1BBA,
0x7A12, 0x8B09, 0x4A2F, 0xBB34, 0x1A68, 0xEB73, 0x2A55, 0xDB4E,
0x4EC3, 0xBFD8, 0x7EFE, 0x8FE5, 0x2EB9, 0xDFA2, 0x1E84, 0xEF9F,
0x8E37, 0x7F2C, 0xBE0A, 0x4F11, 0xEE4D, 0x1F56, 0xDE70, 0x2F6B,
0x1D20, 0xEC3B, 0x2D1D, 0xDC06, 0x7D5A, 0x8C41, 0x4D67, 0xBC7C,
0xDDD4, 0x2CCF, 0xEDE9, 0x1CF2, 0xBDAE, 0x4CB5, 0x8D93, 0x7C88,
0x7482, 0x8599, 0x44BF, 0xB5A4, 0x14F8, 0xE5E3, 0x24C5, 0xD5DE,
0xB476, 0x456D, 0x844B, 0x7550, 0xD40C, 0x2517, 0xE431, 0x152A,
0x2761, 0xD67A, 0x175C, 0xE647, 0x471B, 0xB600, 0x7726, 0x863D,
0xE795, 0x168E, 0xD7A8, 0x26B3, 0x87EF, 0x76F4, 0xB7D2, 0x46C9,
0xD344, 0x225F, 0xE379, 0x1262, 0xB33E, 0x4225, 0x8303, 0x7218,
0x13B0, 0xE2AB, 0x238D, 0xD296, 0x73CA, 0x82D1, 0x43F7, 0xB2EC,
0x80A7, 0x71BC, 0xB09A, 0x4181, 0xE0DD, 0x11C6, 0xD0E0, 0x21FB,
0x4053, 0xB148, 0x706E, 0x8175, 0x2029, 0xD132, 0x1014, 0xE10F
};
readonly UInt16[] Crc16_PolyA097_Table16 = new UInt16[256]
{
0x0000, 0xA097, 0xE1B9, 0x412E, 0x63E5, 0xC372, 0x825C, 0x22CB,
0xC7CA, 0x675D, 0x2673, 0x86E4, 0xA42F, 0x04B8, 0x4596, 0xE501,
0x2F03, 0x8F94, 0xCEBA, 0x6E2D, 0x4CE6, 0xEC71, 0xAD5F, 0x0DC8,
0xE8C9, 0x485E, 0x0970, 0xA9E7, 0x8B2C, 0x2BBB, 0x6A95, 0xCA02,
0x5E06, 0xFE91, 0xBFBF, 0x1F28, 0x3DE3, 0x9D74, 0xDC5A, 0x7CCD,
0x99CC, 0x395B, 0x7875, 0xD8E2, 0xFA29, 0x5ABE, 0x1B90, 0xBB07,
0x7105, 0xD192, 0x90BC, 0x302B, 0x12E0, 0xB277, 0xF359, 0x53CE,
0xB6CF, 0x1658, 0x5776, 0xF7E1, 0xD52A, 0x75BD, 0x3493, 0x9404,
0xBC0C, 0x1C9B, 0x5DB5, 0xFD22, 0xDFE9, 0x7F7E, 0x3E50, 0x9EC7,
0x7BC6, 0xDB51, 0x9A7F, 0x3AE8, 0x1823, 0xB8B4, 0xF99A, 0x590D,
0x930F, 0x3398, 0x72B6, 0xD221, 0xF0EA, 0x507D, 0x1153, 0xB1C4,
0x54C5, 0xF452, 0xB57C, 0x15EB, 0x3720, 0x97B7, 0xD699, 0x760E,
0xE20A, 0x429D, 0x03B3, 0xA324, 0x81EF, 0x2178, 0x6056, 0xC0C1,
0x25C0, 0x8557, 0xC479, 0x64EE, 0x4625, 0xE6B2, 0xA79C, 0x070B,
0xCD09, 0x6D9E, 0x2CB0, 0x8C27, 0xAEEC, 0x0E7B, 0x4F55, 0xEFC2,
0x0AC3, 0xAA54, 0xEB7A, 0x4BED, 0x6926, 0xC9B1, 0x889F, 0x2808,
0xD88F, 0x7818, 0x3936, 0x99A1, 0xBB6A, 0x1BFD, 0x5AD3, 0xFA44,
0x1F45, 0xBFD2, 0xFEFC, 0x5E6B, 0x7CA0, 0xDC37, 0x9D19, 0x3D8E,
0xF78C, 0x571B, 0x1635, 0xB6A2, 0x9469, 0x34FE, 0x75D0, 0xD547,
0x3046, 0x90D1, 0xD1FF, 0x7168, 0x53A3, 0xF334, 0xB21A, 0x128D,
0x8689, 0x261E, 0x6730, 0xC7A7, 0xE56C, 0x45FB, 0x04D5, 0xA442,
0x4143, 0xE1D4, 0xA0FA, 0x006D, 0x22A6, 0x8231, 0xC31F, 0x6388,
0xA98A, 0x091D, 0x4833, 0xE8A4, 0xCA6F, 0x6AF8, 0x2BD6, 0x8B41,
0x6E40, 0xCED7, 0x8FF9, 0x2F6E, 0x0DA5, 0xAD32, 0xEC1C, 0x4C8B,
0x6483, 0xC414, 0x853A, 0x25AD, 0x0766, 0xA7F1, 0xE6DF, 0x4648,
0xA349, 0x03DE, 0x42F0, 0xE267, 0xC0AC, 0x603B, 0x2115, 0x8182,
0x4B80, 0xEB17, 0xAA39, 0x0AAE, 0x2865, 0x88F2, 0xC9DC, 0x694B,
0x8C4A, 0x2CDD, 0x6DF3, 0xCD64, 0xEFAF, 0x4F38, 0x0E16, 0xAE81,
0x3A85, 0x9A12, 0xDB3C, 0x7BAB, 0x5960, 0xF9F7, 0xB8D9, 0x184E,
0xFD4F, 0x5DD8, 0x1CF6, 0xBC61, 0x9EAA, 0x3E3D, 0x7F13, 0xDF84,
0x1586, 0xB511, 0xF43F, 0x54A8, 0x7663, 0xD6F4, 0x97DA, 0x374D,
0xD24C, 0x72DB, 0x33F5, 0x9362, 0xB1A9, 0x113E, 0x5010, 0xF087
};
#endregion
public ushort CRC16_Calculate(Scm_CRC16_InputParameters scm_CRC16_InputParameters)
{
ushort poly = scm_CRC16_InputParameters.Polynomial;
ushort crc = scm_CRC16_InputParameters.InitCrc;
int width = scm_CRC16_InputParameters.cWidth;
//小端模式,反转多项式
if (scm_CRC16_InputParameters.LittleEndian)
poly = SpecialFunctions.ReverseBits.ReverseUInt16(poly);
for (int i = 0; i < scm_CRC16_InputParameters.Datas.Length; i++)
{
byte tempData = scm_CRC16_InputParameters.Datas[i];
//输入反转
if (scm_CRC16_InputParameters.RefIn)
tempData = SpecialFunctions.ReverseBits.ReverseUInt8(tempData);
if (scm_CRC16_InputParameters.LittleEndian)
crc ^= (ushort)(tempData & 0xff);
else
//左移到最高字节,然后与初始值异或
crc ^= (ushort)(tempData << (width - 8));
for (int j = 0; j < 8; j++)
{
if (scm_CRC16_InputParameters.LittleEndian)
{//小端模式
//最低位为1,异或多项式
if ((crc & 0x01) != 0)
{
crc >>= 1;
crc ^= poly;
}
else
crc >>= 1;
}
else
{
//最高位为1,异或多项式
if ((crc & ((ushort)1 << (width - 1))) != 0)
{
crc <<= 1;
crc ^= poly;
}
else
crc <<= 1;
}
}
}
//输出反转
if (scm_CRC16_InputParameters.RefOut)
crc = SpecialFunctions.ReverseBits.ReverseUInt16(crc);
//输出异或
//if (scm_CRC16_InputParameters.isOutputXor)
crc ^= scm_CRC16_InputParameters.XorOut;
return crc;
}
public ushort[] GetCRC16_ByteTable_1(uint poly)
{
ushort[] table = new ushort[256];
byte width = 16;
for (int i = 0; i < 256; i++)
{
string proInfo = "";
proInfo += "i value:" + SpecialFunctions.MyStringConverter.DataToBinaryString(new byte[1] { (byte)i }) + "\r\n";
uint tableValue = 0;
byte index = 0;
for (int j = 7; j >= 0; j--)
{
//确保将数据 使用poly多次异或的高位 全部异或掉
byte tempFor = (byte)(((byte)i) ^ index);
byte currentMsb = (byte)(tempFor >> j);
if ((currentMsb & 0x01) == 0x01) //当前最高位是1,要与poly异或
{
tableValue ^= (poly << j); //去掉高位剩下的值,第一次要去掉高7位
byte temp = (byte)(poly >> (width - j));//取高位作为索引
index ^= temp;
proInfo += "j=" + j.ToString() + ", currentM:" + SpecialFunctions.MyStringConverter.DataToBinaryString(new byte[1] { (byte)temp }) + ", index value:" + SpecialFunctions.MyStringConverter.DataToBinaryString(new byte[1] { (byte)index }) + "\r\n";
}
}
proInfo += "index value:" + SpecialFunctions.MyStringConverter.DataToBinaryString(new byte[1] { (byte)index }) + "\r\n";
if (i != index)
Console.WriteLine("Error: i:{0}, index:{1}, detail:\r\n{2}", i, index, proInfo);
table[index] = (ushort)tableValue;
}
return table;
}
public ushort[] GetCRC16_ByteTable_2(ushort poly)
{
ushort[] table = new ushort[256];
byte width = 16;
for (int i = 0; i < 256; i++)
{
string proInfo = "";
proInfo += "i value:" + SpecialFunctions.MyStringConverter.DataToBinaryString(new byte[1] { (byte)i }) + "\r\n";
ushort tableValue = 0;
byte index = 0;
for (int j = 7; j >= 0; j--)
{
//确保将数据 使用poly多次异或的高位 全部异或掉
byte tempFor = (byte)(((byte)i) ^ index);
byte currentMsb = (byte)(tempFor >> j);
if ((currentMsb & 0x01) == 0x01) //当前最高位是1,要与poly异或
{
tableValue ^= (ushort)(poly << j); //去掉高位剩下的值,第一次要去掉高7位
byte temp = (byte)( (poly >> (width - j)) | (1<
/// CRC16
/// 字节查表法
///
ushort CRC16_CalCrcByByte(Scm_CRC16_InputParameters scm_CRC16_InputParameters)
{
ushort poly = scm_CRC16_InputParameters.Polynomial;
ushort crc = scm_CRC16_InputParameters.InitCrc;
int width = scm_CRC16_InputParameters.cWidth;
//小端模式,反转多项式
if (scm_CRC16_InputParameters.LittleEndian)
poly = SpecialFunctions.ReverseBits.ReverseUInt16(poly);
for (int i = 0; i < scm_CRC16_InputParameters.Datas.Length; i++)
{
byte tempData = scm_CRC16_InputParameters.Datas[i];
//输入反转
if (scm_CRC16_InputParameters.RefIn)
tempData = SpecialFunctions.ReverseBits.ReverseUInt8(tempData);
byte index = 0;
//异或的部分最终会消除掉,这里我们就不将其存到CRC了
if (scm_CRC16_InputParameters.LittleEndian)
//最低字节与初始值异或
index = (byte)( crc ^ tempData );
else
//左移到最高字节,然后与初始值异或
index = (byte)( (crc >> (width - 8)) ^ tempData );
switch (poly)
{
case 0x1021:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_Poly1021_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_Poly1021_Table16[index]);
break;
case 0x8005:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_Poly8005_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_Poly8005_Table16[index]);
break;
case 0xC867:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_PolyC867_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_PolyC867_Table16[index]);
break;
case 0x0589:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_Poly0589_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_Poly0589_Table16[index]);
break;
case 0x3D65:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_Poly3D65_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_Poly3D65_Table16[index]);
break;
case 0x8BB7:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_Poly8BB7_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_Poly8BB7_Table16[index]);
break;
case 0xA097:
if (scm_CRC16_InputParameters.LittleEndian)
crc = (ushort)((crc >> 8) ^ Crc16_PolyA097_Table16_Reflect[index]);
else
crc = (ushort)((crc << 8) ^ Crc16_PolyA097_Table16[index]);
break;
default:
crc = 0;
break;
}
}
//输出反转
if (scm_CRC16_InputParameters.RefOut)
crc = SpecialFunctions.ReverseBits.ReverseUInt16(crc);
//输出异或
//if (scm_CRC16_InputParameters.isOutputXor)
crc ^= scm_CRC16_InputParameters.XorOut;
return crc;
}
private void CalCrc16All(byte[] data)
{
//计算网页地址:https://crccalc.com/
//网址2:https://emn178.github.io/online-tools/crc16.html
Scm_CRC16_InputParameters[] scm_CRC16_InputParametersList = new Scm_CRC16_InputParameters[] {
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/CCITT-FALSE", Polynomial= 0x1021, InitCrc=0xFFFF, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/ARC ", Polynomial= 0x8005, InitCrc=0x0000, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/AUG-CCITT ", Polynomial= 0x1021, InitCrc=0x1D0F, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/BUYPASS ", Polynomial= 0x8005, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/CDMA2000 ", Polynomial= 0xC867, InitCrc=0xFFFF, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/DDS-110 ", Polynomial= 0x8005, InitCrc=0x800D, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/DECT-R ", Polynomial= 0x0589, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0001 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/DECT-X ", Polynomial= 0x0589, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/DNP ", Polynomial= 0x3D65, InitCrc=0x0000, RefIn=true, RefOut=true, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/EN-13757 ", Polynomial= 0x3D65, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/GENIBUS ", Polynomial= 0x1021, InitCrc=0xFFFF, RefIn=false, RefOut=false, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/MAXIM ", Polynomial= 0x8005, InitCrc=0x0000, RefIn=true, RefOut=true, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/MCRF4XX ", Polynomial= 0x1021, InitCrc=0xFFFF, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/RIELLO ", Polynomial= 0x1021, InitCrc=0xB2AA, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/T10-DIF ", Polynomial= 0x8BB7, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/TELEDISK ", Polynomial= 0xA097, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/TMS37157 ", Polynomial= 0x1021, InitCrc=0x89EC, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/USB ", Polynomial= 0x8005, InitCrc=0xFFFF, RefIn=true, RefOut=true, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-A ", Polynomial= 0x1021, InitCrc=0xC6C6, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/KERMIT ", Polynomial= 0x1021, InitCrc=0x0000, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/MODBUS ", Polynomial= 0x8005, InitCrc=0xFFFF, RefIn=true, RefOut=true, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/X-25 ", Polynomial= 0x1021, InitCrc=0xFFFF, RefIn=true, RefOut=true, XorOut=0xFFFF ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)},
new Scm_CRC16_InputParameters(){ AlgorithmName ="CRC-16/XMODEM ", Polynomial= 0x1021, InitCrc=0x0000, RefIn=false, RefOut=false, XorOut=0x0000 ,Datas=SpecialFunctions.ArrayCopy.CopyArray(data)}
};
for (int i = 0; i < scm_CRC16_InputParametersList.Length; i++)
{
//scm_CRC16_InputParametersList[i].Datas = SpecialFunctions.ArrayCopy.CopyArray(data);
ushort crc1 = CRC16_Calculate(scm_CRC16_InputParametersList[i]);
Console.WriteLine("BitsCal {0}, Poly={1:X04}, InitCrc={2:X04}, RefIn={3}, RefOut={4}, XorOut={5:X04}, data={6}, result={7:X04}",
scm_CRC16_InputParametersList[i].AlgorithmName,
scm_CRC16_InputParametersList[i].Polynomial, scm_CRC16_InputParametersList[i].InitCrc,
(scm_CRC16_InputParametersList[i].RefIn ? "True " : "False"), (scm_CRC16_InputParametersList[i].RefOut ? "True " : "False"),
scm_CRC16_InputParametersList[i].XorOut, BitConverter.ToString(scm_CRC16_InputParametersList[i].Datas).Replace("-", ""),
crc1);
ushort crc2 = CRC16_CalCrcByByte(scm_CRC16_InputParametersList[i]);
Console.WriteLine("ByteCal {0}, Poly={1:X04}, InitCrc={2:X04}, RefIn={3}, RefOut={4}, XorOut={5:X04}, data={6}, result={7:X04}",
scm_CRC16_InputParametersList[i].AlgorithmName,
scm_CRC16_InputParametersList[i].Polynomial, scm_CRC16_InputParametersList[i].InitCrc,
(scm_CRC16_InputParametersList[i].RefIn ? "True " : "False"), (scm_CRC16_InputParametersList[i].RefOut ? "True " : "False"),
scm_CRC16_InputParametersList[i].XorOut, BitConverter.ToString(scm_CRC16_InputParametersList[i].Datas).Replace("-", ""),
crc2);
if (crc1 != crc2)
{
ConsoleColor temp = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Not Same");
Console.ForegroundColor = temp;
}
}
}
private void GetTableTest_1()
{
UInt16[] polyList = new UInt16[] { 0x1021, 0x8005, 0xC867, 0x0589, 0x3D65, 0x8BB7, 0xA097 };
for (int pp = 0; pp < polyList.Length; pp++)
{
Console.Write("Get Poly {0:X04} table:", polyList[pp]);
ushort[] table1 = GetCRC16_ByteTable_1((uint)(polyList[pp]+ (1<<16)) );
ushort[] table2 = GetCRC16_ByteTable_2(polyList[pp]);
ushort[] table3 = GetCRC16_ByteTable_3(polyList[pp], false);
for (int i = 0; i < table1.Length; i++)
{
if (i % 8 == 0)
{
Console.WriteLine();
Console.Write("\t");
}
//Console.Write("0x{0:X04}, ", table[i]);
if (table1[i] != table2[i] || table1[i] != table3[i] || table3[i] != table2[i])
Console.Write("not same: i={0}, {1:X03}, {2:X03}, {3:X03}", i, table1[i], table2[i], table3[i]);
}
}
}
private void GetTableTest_2()
{
UInt16[] polyList = new UInt16[] { 0x1021, 0x8005, 0xC867, 0x0589, 0x3D65, 0x8BB7, 0xA097 };
for (int pp = 0; pp < polyList.Length; pp++)
{
bool[] littleEndian = new bool[] { true, false };
for (int ss = 0; ss < littleEndian.Length; ss++)
{
Console.WriteLine("readonly UInt16[] Crc16_Poly" + polyList[pp].ToString("X04") + "_Table16" + (littleEndian[ss]?"_Reflect":"") +" = new UInt16[256]\r\n{");
UInt16[] table = GetCRC16_ByteTable_3(polyList[pp],littleEndian[ss]);
//UInt16[] table = GetCRC16_ByteTable_1((uint)(polyList[pp] + (1 << 16)));
for (int i = 0; i < table.Length; i++)
{
if (i % 8 == 0)
Console.WriteLine();
if (i < table.Length - 1)
Console.Write("0x{0:X04}, ", table[i]);
else
{
Console.Write("0x{0:X04}\r\n", table[i]);
Console.WriteLine(@"};");
Console.WriteLine();
}
}
}
}
Console.WriteLine();
}
public static void Test(byte[] data, ushort crcInitial)
{
CRC16 cRC16 = new CRC16();
cRC16.CalCrc16All(data);
//cRC16.GetTableTest_1();
//cRC16.GetTableTest_2();
}
}
}
上一篇 【CRC】CRC推导(五)CRC8的各种实现 下一篇 【CRC】CRC推导(七)CRC32的各种实现