1 ///**********************************************************************2 ///Name: CRC-4/ITU x4+x+13 ///Poly: 0x034 ///Init: 0x005 ///Refin: true6 ///Refout: true7 ///Xorout: 0x008 ///*************************************************************************
9 public static byte[] Crc1(byte[] buffer, int start = 0, int len = 0)10 {11 if (buffer == null || buffer.Length == 0) return null;12 if (start < 0) return null;13 if (len == 0) len = buffer.Length -start;14 int length = start +len;15 if (length > buffer.Length) return null;16 byte crc = 0;//Initial value
17 for (int i = start; i < length; i++)18 {19 crc ^=buffer[i];20 for (int j = 0; j < 8; j++)21 {22 if ((crc & 1) > 0)23 crc = (byte)((crc >> 1) ^ 0x0C);//0x0C = (reverse 0x03)>>(8-4)
24 else
25 crc = (byte)(crc >> 1);26 }27 }28 return new byte[] { crc };29 }30 ///**********************************************************************31 ///Name: CRC-5/EPC x5+x3+132 ///Poly: 0x0933 ///Init: 0x0934 ///Refin: false35 ///Refout: false36 ///Xorout: 0x0037 ///*************************************************************************
38 public static byte[] Crc2(byte[] buffer, int start = 0, int len = 0)39 {40 if (buffer == null || buffer.Length == 0) return null;41 if (start < 0) return null;42 if (len == 0) len = buffer.Length -start;43 int length = start +len;44 if (length > buffer.Length) return null;45 byte crc = 0x48;//Initial value: 0x48 = 0x09<
46 for (int i = start; i < length; i++)47 {48 crc ^=buffer[i];49 for (int j = 0; j < 8; j++)50 {51 if ((crc & 0x80) > 0)52 crc = (byte)((crc << 1) ^ 0x48);//0x48 = 0x09<
53 else
54 crc = (byte)(crc << 1);55 }56 }57 return new byte[] { (byte)(crc >> 3) };58 }59 ///**********************************************************************60 ///Name: CRC-5/ITU x5+x4+x2+161 ///Poly: 0x1562 ///Init: 0x0063 ///Refin: true64 ///Refout: true65 ///Xorout: 0x0066 ///*************************************************************************
67 public static byte[] Crc3(byte[] buffer, int start = 0, int len = 0)68 {69 if (buffer == null || buffer.Length == 0) return null;70 if (start < 0) return null;71 if (len == 0) len = buffer.Length -start;72 int length = start +len;73 if (length > buffer.Length) return null;74 byte crc = 0;//Initial value
75 for (int i = start; i < length; i++)76 {77 crc ^=buffer[i];78 for (int j = 0; j < 8; j++)79 {80 if ((crc & 1) > 0)81 crc = (byte)((crc >> 1) ^ 0x15);//0x15 = (reverse 0x15)>>(8-5)
82 else
83 crc = (byte)(crc >> 1);84 }85 }86 return new byte[] { crc };87 }88 ///**********************************************************************89 ///Name: CRC-5/USB x5+x2+190 ///Poly: 0x0591 ///Init: 0x1F92 ///Refin: true93 ///Refout: true94 ///Xorout: 0x1F95 ///*************************************************************************
96 public static byte[] Crc4(byte[] buffer, int start = 0, int len = 0)97 {98 if (buffer == null || buffer.Length == 0) return null;99 if (start < 0) return null;100 if (len == 0) len = buffer.Length -start;101 int length = start +len;102 if (length > buffer.Length) return null;103 byte crc = 0x1F;//Initial value
104 for (int i = start; i < length; i++)105 {106 crc ^=buffer[i];107 for (int j = 0; j < 8; j++)108 {109 if ((crc & 1) > 0)110 crc = (byte)((crc >> 1) ^ 0x14);//0x14 = (reverse 0x05)>>(8-5)
111 else
112 crc = (byte)(crc >> 1);113 }114 }115 return new byte[] {(byte)( crc ^ 0x1F) };116 }117 ///**********************************************************************118 ///Name: CRC-6/ITU x6+x+1119 ///Poly: 0x03120 ///Init: 0x00121 ///Refin: true122 ///Refout: true123 ///Xorout: 0x00124 ///*************************************************************************
125 public static byte[] Crc5(byte[] buffer, int start = 0, int len = 0)126 {127 if (buffer == null || buffer.Length == 0) return null;128 if (start < 0) return null;129 if (len == 0) len = buffer.Length -start;130 int length = start +len;131 if (length > buffer.Length) return null;132 byte crc = 0;//Initial value
133 for (int i = start; i < length; i++)134 {135 crc ^=buffer[i];136 for (int j = 0; j < 8; j++)137 {138 if ((crc & 1) > 0)139 crc = (byte)((crc >> 1) ^ 0x30);//0x30 = (reverse 0x03)>>(8-6)
140 else
141 crc = (byte)(crc >> 1);142 }143 }144 return new byte[] { crc };145 }146 ///**********************************************************************147 ///Name: CRC-7/MMC x7+x3+