-
Notifications
You must be signed in to change notification settings - Fork 4
/
fit_FastCrc.cs
317 lines (313 loc) · 20 KB
/
fit_FastCrc.cs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using System;
using System.IO;
namespace FitParser.Core
{
// Fast 64 bit 8x256 lookup table for CRC16 algorithm
// Inspiration/credit to Matt Stancliff, author of CRC speed: https://matt.sh/redis-crcspeed
// This implementation is for the CRC16 variant of the CRC algorithm
public static class Crc16
{
// This table was generated by the CrcTableGenerator program in the
// source distribution.
private static ushort[,] Crc16Table = {
{
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,
},
{
0x0000, 0x9001, 0x6001, 0xf000, 0xc002, 0x5003, 0xa003, 0x3002,
0xc007, 0x5006, 0xa006, 0x3007, 0x0005, 0x9004, 0x6004, 0xf005,
0xc00d, 0x500c, 0xa00c, 0x300d, 0x000f, 0x900e, 0x600e, 0xf00f,
0x000a, 0x900b, 0x600b, 0xf00a, 0xc008, 0x5009, 0xa009, 0x3008,
0xc019, 0x5018, 0xa018, 0x3019, 0x001b, 0x901a, 0x601a, 0xf01b,
0x001e, 0x901f, 0x601f, 0xf01e, 0xc01c, 0x501d, 0xa01d, 0x301c,
0x0014, 0x9015, 0x6015, 0xf014, 0xc016, 0x5017, 0xa017, 0x3016,
0xc013, 0x5012, 0xa012, 0x3013, 0x0011, 0x9010, 0x6010, 0xf011,
0xc031, 0x5030, 0xa030, 0x3031, 0x0033, 0x9032, 0x6032, 0xf033,
0x0036, 0x9037, 0x6037, 0xf036, 0xc034, 0x5035, 0xa035, 0x3034,
0x003c, 0x903d, 0x603d, 0xf03c, 0xc03e, 0x503f, 0xa03f, 0x303e,
0xc03b, 0x503a, 0xa03a, 0x303b, 0x0039, 0x9038, 0x6038, 0xf039,
0x0028, 0x9029, 0x6029, 0xf028, 0xc02a, 0x502b, 0xa02b, 0x302a,
0xc02f, 0x502e, 0xa02e, 0x302f, 0x002d, 0x902c, 0x602c, 0xf02d,
0xc025, 0x5024, 0xa024, 0x3025, 0x0027, 0x9026, 0x6026, 0xf027,
0x0022, 0x9023, 0x6023, 0xf022, 0xc020, 0x5021, 0xa021, 0x3020,
0xc061, 0x5060, 0xa060, 0x3061, 0x0063, 0x9062, 0x6062, 0xf063,
0x0066, 0x9067, 0x6067, 0xf066, 0xc064, 0x5065, 0xa065, 0x3064,
0x006c, 0x906d, 0x606d, 0xf06c, 0xc06e, 0x506f, 0xa06f, 0x306e,
0xc06b, 0x506a, 0xa06a, 0x306b, 0x0069, 0x9068, 0x6068, 0xf069,
0x0078, 0x9079, 0x6079, 0xf078, 0xc07a, 0x507b, 0xa07b, 0x307a,
0xc07f, 0x507e, 0xa07e, 0x307f, 0x007d, 0x907c, 0x607c, 0xf07d,
0xc075, 0x5074, 0xa074, 0x3075, 0x0077, 0x9076, 0x6076, 0xf077,
0x0072, 0x9073, 0x6073, 0xf072, 0xc070, 0x5071, 0xa071, 0x3070,
0x0050, 0x9051, 0x6051, 0xf050, 0xc052, 0x5053, 0xa053, 0x3052,
0xc057, 0x5056, 0xa056, 0x3057, 0x0055, 0x9054, 0x6054, 0xf055,
0xc05d, 0x505c, 0xa05c, 0x305d, 0x005f, 0x905e, 0x605e, 0xf05f,
0x005a, 0x905b, 0x605b, 0xf05a, 0xc058, 0x5059, 0xa059, 0x3058,
0xc049, 0x5048, 0xa048, 0x3049, 0x004b, 0x904a, 0x604a, 0xf04b,
0x004e, 0x904f, 0x604f, 0xf04e, 0xc04c, 0x504d, 0xa04d, 0x304c,
0x0044, 0x9045, 0x6045, 0xf044, 0xc046, 0x5047, 0xa047, 0x3046,
0xc043, 0x5042, 0xa042, 0x3043, 0x0041, 0x9040, 0x6040, 0xf041,
},
{
0x0000, 0xc051, 0xc0a1, 0x00f0, 0xc141, 0x0110, 0x01e0, 0xc1b1,
0xc281, 0x02d0, 0x0220, 0xc271, 0x03c0, 0xc391, 0xc361, 0x0330,
0xc501, 0x0550, 0x05a0, 0xc5f1, 0x0440, 0xc411, 0xc4e1, 0x04b0,
0x0780, 0xc7d1, 0xc721, 0x0770, 0xc6c1, 0x0690, 0x0660, 0xc631,
0xca01, 0x0a50, 0x0aa0, 0xcaf1, 0x0b40, 0xcb11, 0xcbe1, 0x0bb0,
0x0880, 0xc8d1, 0xc821, 0x0870, 0xc9c1, 0x0990, 0x0960, 0xc931,
0x0f00, 0xcf51, 0xcfa1, 0x0ff0, 0xce41, 0x0e10, 0x0ee0, 0xceb1,
0xcd81, 0x0dd0, 0x0d20, 0xcd71, 0x0cc0, 0xcc91, 0xcc61, 0x0c30,
0xd401, 0x1450, 0x14a0, 0xd4f1, 0x1540, 0xd511, 0xd5e1, 0x15b0,
0x1680, 0xd6d1, 0xd621, 0x1670, 0xd7c1, 0x1790, 0x1760, 0xd731,
0x1100, 0xd151, 0xd1a1, 0x11f0, 0xd041, 0x1010, 0x10e0, 0xd0b1,
0xd381, 0x13d0, 0x1320, 0xd371, 0x12c0, 0xd291, 0xd261, 0x1230,
0x1e00, 0xde51, 0xdea1, 0x1ef0, 0xdf41, 0x1f10, 0x1fe0, 0xdfb1,
0xdc81, 0x1cd0, 0x1c20, 0xdc71, 0x1dc0, 0xdd91, 0xdd61, 0x1d30,
0xdb01, 0x1b50, 0x1ba0, 0xdbf1, 0x1a40, 0xda11, 0xdae1, 0x1ab0,
0x1980, 0xd9d1, 0xd921, 0x1970, 0xd8c1, 0x1890, 0x1860, 0xd831,
0xe801, 0x2850, 0x28a0, 0xe8f1, 0x2940, 0xe911, 0xe9e1, 0x29b0,
0x2a80, 0xead1, 0xea21, 0x2a70, 0xebc1, 0x2b90, 0x2b60, 0xeb31,
0x2d00, 0xed51, 0xeda1, 0x2df0, 0xec41, 0x2c10, 0x2ce0, 0xecb1,
0xef81, 0x2fd0, 0x2f20, 0xef71, 0x2ec0, 0xee91, 0xee61, 0x2e30,
0x2200, 0xe251, 0xe2a1, 0x22f0, 0xe341, 0x2310, 0x23e0, 0xe3b1,
0xe081, 0x20d0, 0x2020, 0xe071, 0x21c0, 0xe191, 0xe161, 0x2130,
0xe701, 0x2750, 0x27a0, 0xe7f1, 0x2640, 0xe611, 0xe6e1, 0x26b0,
0x2580, 0xe5d1, 0xe521, 0x2570, 0xe4c1, 0x2490, 0x2460, 0xe431,
0x3c00, 0xfc51, 0xfca1, 0x3cf0, 0xfd41, 0x3d10, 0x3de0, 0xfdb1,
0xfe81, 0x3ed0, 0x3e20, 0xfe71, 0x3fc0, 0xff91, 0xff61, 0x3f30,
0xf901, 0x3950, 0x39a0, 0xf9f1, 0x3840, 0xf811, 0xf8e1, 0x38b0,
0x3b80, 0xfbd1, 0xfb21, 0x3b70, 0xfac1, 0x3a90, 0x3a60, 0xfa31,
0xf601, 0x3650, 0x36a0, 0xf6f1, 0x3740, 0xf711, 0xf7e1, 0x37b0,
0x3480, 0xf4d1, 0xf421, 0x3470, 0xf5c1, 0x3590, 0x3560, 0xf531,
0x3300, 0xf351, 0xf3a1, 0x33f0, 0xf241, 0x3210, 0x32e0, 0xf2b1,
0xf181, 0x31d0, 0x3120, 0xf171, 0x30c0, 0xf091, 0xf061, 0x3030,
},
{
0x0000, 0xfc01, 0xb801, 0x4400, 0x3001, 0xcc00, 0x8800, 0x7401,
0x6002, 0x9c03, 0xd803, 0x2402, 0x5003, 0xac02, 0xe802, 0x1403,
0xc004, 0x3c05, 0x7805, 0x8404, 0xf005, 0x0c04, 0x4804, 0xb405,
0xa006, 0x5c07, 0x1807, 0xe406, 0x9007, 0x6c06, 0x2806, 0xd407,
0xc00b, 0x3c0a, 0x780a, 0x840b, 0xf00a, 0x0c0b, 0x480b, 0xb40a,
0xa009, 0x5c08, 0x1808, 0xe409, 0x9008, 0x6c09, 0x2809, 0xd408,
0x000f, 0xfc0e, 0xb80e, 0x440f, 0x300e, 0xcc0f, 0x880f, 0x740e,
0x600d, 0x9c0c, 0xd80c, 0x240d, 0x500c, 0xac0d, 0xe80d, 0x140c,
0xc015, 0x3c14, 0x7814, 0x8415, 0xf014, 0x0c15, 0x4815, 0xb414,
0xa017, 0x5c16, 0x1816, 0xe417, 0x9016, 0x6c17, 0x2817, 0xd416,
0x0011, 0xfc10, 0xb810, 0x4411, 0x3010, 0xcc11, 0x8811, 0x7410,
0x6013, 0x9c12, 0xd812, 0x2413, 0x5012, 0xac13, 0xe813, 0x1412,
0x001e, 0xfc1f, 0xb81f, 0x441e, 0x301f, 0xcc1e, 0x881e, 0x741f,
0x601c, 0x9c1d, 0xd81d, 0x241c, 0x501d, 0xac1c, 0xe81c, 0x141d,
0xc01a, 0x3c1b, 0x781b, 0x841a, 0xf01b, 0x0c1a, 0x481a, 0xb41b,
0xa018, 0x5c19, 0x1819, 0xe418, 0x9019, 0x6c18, 0x2818, 0xd419,
0xc029, 0x3c28, 0x7828, 0x8429, 0xf028, 0x0c29, 0x4829, 0xb428,
0xa02b, 0x5c2a, 0x182a, 0xe42b, 0x902a, 0x6c2b, 0x282b, 0xd42a,
0x002d, 0xfc2c, 0xb82c, 0x442d, 0x302c, 0xcc2d, 0x882d, 0x742c,
0x602f, 0x9c2e, 0xd82e, 0x242f, 0x502e, 0xac2f, 0xe82f, 0x142e,
0x0022, 0xfc23, 0xb823, 0x4422, 0x3023, 0xcc22, 0x8822, 0x7423,
0x6020, 0x9c21, 0xd821, 0x2420, 0x5021, 0xac20, 0xe820, 0x1421,
0xc026, 0x3c27, 0x7827, 0x8426, 0xf027, 0x0c26, 0x4826, 0xb427,
0xa024, 0x5c25, 0x1825, 0xe424, 0x9025, 0x6c24, 0x2824, 0xd425,
0x003c, 0xfc3d, 0xb83d, 0x443c, 0x303d, 0xcc3c, 0x883c, 0x743d,
0x603e, 0x9c3f, 0xd83f, 0x243e, 0x503f, 0xac3e, 0xe83e, 0x143f,
0xc038, 0x3c39, 0x7839, 0x8438, 0xf039, 0x0c38, 0x4838, 0xb439,
0xa03a, 0x5c3b, 0x183b, 0xe43a, 0x903b, 0x6c3a, 0x283a, 0xd43b,
0xc037, 0x3c36, 0x7836, 0x8437, 0xf036, 0x0c37, 0x4837, 0xb436,
0xa035, 0x5c34, 0x1834, 0xe435, 0x9034, 0x6c35, 0x2835, 0xd434,
0x0033, 0xfc32, 0xb832, 0x4433, 0x3032, 0xcc33, 0x8833, 0x7432,
0x6031, 0x9c30, 0xd830, 0x2431, 0x5030, 0xac31, 0xe831, 0x1430,
},
{
0x0000, 0xc03d, 0xc079, 0x0044, 0xc0f1, 0x00cc, 0x0088, 0xc0b5,
0xc1e1, 0x01dc, 0x0198, 0xc1a5, 0x0110, 0xc12d, 0xc169, 0x0154,
0xc3c1, 0x03fc, 0x03b8, 0xc385, 0x0330, 0xc30d, 0xc349, 0x0374,
0x0220, 0xc21d, 0xc259, 0x0264, 0xc2d1, 0x02ec, 0x02a8, 0xc295,
0xc781, 0x07bc, 0x07f8, 0xc7c5, 0x0770, 0xc74d, 0xc709, 0x0734,
0x0660, 0xc65d, 0xc619, 0x0624, 0xc691, 0x06ac, 0x06e8, 0xc6d5,
0x0440, 0xc47d, 0xc439, 0x0404, 0xc4b1, 0x048c, 0x04c8, 0xc4f5,
0xc5a1, 0x059c, 0x05d8, 0xc5e5, 0x0550, 0xc56d, 0xc529, 0x0514,
0xcf01, 0x0f3c, 0x0f78, 0xcf45, 0x0ff0, 0xcfcd, 0xcf89, 0x0fb4,
0x0ee0, 0xcedd, 0xce99, 0x0ea4, 0xce11, 0x0e2c, 0x0e68, 0xce55,
0x0cc0, 0xccfd, 0xccb9, 0x0c84, 0xcc31, 0x0c0c, 0x0c48, 0xcc75,
0xcd21, 0x0d1c, 0x0d58, 0xcd65, 0x0dd0, 0xcded, 0xcda9, 0x0d94,
0x0880, 0xc8bd, 0xc8f9, 0x08c4, 0xc871, 0x084c, 0x0808, 0xc835,
0xc961, 0x095c, 0x0918, 0xc925, 0x0990, 0xc9ad, 0xc9e9, 0x09d4,
0xcb41, 0x0b7c, 0x0b38, 0xcb05, 0x0bb0, 0xcb8d, 0xcbc9, 0x0bf4,
0x0aa0, 0xca9d, 0xcad9, 0x0ae4, 0xca51, 0x0a6c, 0x0a28, 0xca15,
0xde01, 0x1e3c, 0x1e78, 0xde45, 0x1ef0, 0xdecd, 0xde89, 0x1eb4,
0x1fe0, 0xdfdd, 0xdf99, 0x1fa4, 0xdf11, 0x1f2c, 0x1f68, 0xdf55,
0x1dc0, 0xddfd, 0xddb9, 0x1d84, 0xdd31, 0x1d0c, 0x1d48, 0xdd75,
0xdc21, 0x1c1c, 0x1c58, 0xdc65, 0x1cd0, 0xdced, 0xdca9, 0x1c94,
0x1980, 0xd9bd, 0xd9f9, 0x19c4, 0xd971, 0x194c, 0x1908, 0xd935,
0xd861, 0x185c, 0x1818, 0xd825, 0x1890, 0xd8ad, 0xd8e9, 0x18d4,
0xda41, 0x1a7c, 0x1a38, 0xda05, 0x1ab0, 0xda8d, 0xdac9, 0x1af4,
0x1ba0, 0xdb9d, 0xdbd9, 0x1be4, 0xdb51, 0x1b6c, 0x1b28, 0xdb15,
0x1100, 0xd13d, 0xd179, 0x1144, 0xd1f1, 0x11cc, 0x1188, 0xd1b5,
0xd0e1, 0x10dc, 0x1098, 0xd0a5, 0x1010, 0xd02d, 0xd069, 0x1054,
0xd2c1, 0x12fc, 0x12b8, 0xd285, 0x1230, 0xd20d, 0xd249, 0x1274,
0x1320, 0xd31d, 0xd359, 0x1364, 0xd3d1, 0x13ec, 0x13a8, 0xd395,
0xd681, 0x16bc, 0x16f8, 0xd6c5, 0x1670, 0xd64d, 0xd609, 0x1634,
0x1760, 0xd75d, 0xd719, 0x1724, 0xd791, 0x17ac, 0x17e8, 0xd7d5,
0x1540, 0xd57d, 0xd539, 0x1504, 0xd5b1, 0x158c, 0x15c8, 0xd5f5,
0xd4a1, 0x149c, 0x14d8, 0xd4e5, 0x1450, 0xd46d, 0xd429, 0x1414,
},
{
0x0000, 0xd101, 0xe201, 0x3300, 0x8401, 0x5500, 0x6600, 0xb701,
0x4801, 0x9900, 0xaa00, 0x7b01, 0xcc00, 0x1d01, 0x2e01, 0xff00,
0x9002, 0x4103, 0x7203, 0xa302, 0x1403, 0xc502, 0xf602, 0x2703,
0xd803, 0x0902, 0x3a02, 0xeb03, 0x5c02, 0x8d03, 0xbe03, 0x6f02,
0x6007, 0xb106, 0x8206, 0x5307, 0xe406, 0x3507, 0x0607, 0xd706,
0x2806, 0xf907, 0xca07, 0x1b06, 0xac07, 0x7d06, 0x4e06, 0x9f07,
0xf005, 0x2104, 0x1204, 0xc305, 0x7404, 0xa505, 0x9605, 0x4704,
0xb804, 0x6905, 0x5a05, 0x8b04, 0x3c05, 0xed04, 0xde04, 0x0f05,
0xc00e, 0x110f, 0x220f, 0xf30e, 0x440f, 0x950e, 0xa60e, 0x770f,
0x880f, 0x590e, 0x6a0e, 0xbb0f, 0x0c0e, 0xdd0f, 0xee0f, 0x3f0e,
0x500c, 0x810d, 0xb20d, 0x630c, 0xd40d, 0x050c, 0x360c, 0xe70d,
0x180d, 0xc90c, 0xfa0c, 0x2b0d, 0x9c0c, 0x4d0d, 0x7e0d, 0xaf0c,
0xa009, 0x7108, 0x4208, 0x9309, 0x2408, 0xf509, 0xc609, 0x1708,
0xe808, 0x3909, 0x0a09, 0xdb08, 0x6c09, 0xbd08, 0x8e08, 0x5f09,
0x300b, 0xe10a, 0xd20a, 0x030b, 0xb40a, 0x650b, 0x560b, 0x870a,
0x780a, 0xa90b, 0x9a0b, 0x4b0a, 0xfc0b, 0x2d0a, 0x1e0a, 0xcf0b,
0xc01f, 0x111e, 0x221e, 0xf31f, 0x441e, 0x951f, 0xa61f, 0x771e,
0x881e, 0x591f, 0x6a1f, 0xbb1e, 0x0c1f, 0xdd1e, 0xee1e, 0x3f1f,
0x501d, 0x811c, 0xb21c, 0x631d, 0xd41c, 0x051d, 0x361d, 0xe71c,
0x181c, 0xc91d, 0xfa1d, 0x2b1c, 0x9c1d, 0x4d1c, 0x7e1c, 0xaf1d,
0xa018, 0x7119, 0x4219, 0x9318, 0x2419, 0xf518, 0xc618, 0x1719,
0xe819, 0x3918, 0x0a18, 0xdb19, 0x6c18, 0xbd19, 0x8e19, 0x5f18,
0x301a, 0xe11b, 0xd21b, 0x031a, 0xb41b, 0x651a, 0x561a, 0x871b,
0x781b, 0xa91a, 0x9a1a, 0x4b1b, 0xfc1a, 0x2d1b, 0x1e1b, 0xcf1a,
0x0011, 0xd110, 0xe210, 0x3311, 0x8410, 0x5511, 0x6611, 0xb710,
0x4810, 0x9911, 0xaa11, 0x7b10, 0xcc11, 0x1d10, 0x2e10, 0xff11,
0x9013, 0x4112, 0x7212, 0xa313, 0x1412, 0xc513, 0xf613, 0x2712,
0xd812, 0x0913, 0x3a13, 0xeb12, 0x5c13, 0x8d12, 0xbe12, 0x6f13,
0x6016, 0xb117, 0x8217, 0x5316, 0xe417, 0x3516, 0x0616, 0xd717,
0x2817, 0xf916, 0xca16, 0x1b17, 0xac16, 0x7d17, 0x4e17, 0x9f16,
0xf014, 0x2115, 0x1215, 0xc314, 0x7415, 0xa514, 0x9614, 0x4715,
0xb815, 0x6914, 0x5a14, 0x8b15, 0x3c14, 0xed15, 0xde15, 0x0f14,
},
{
0x0000, 0xc010, 0xc023, 0x0033, 0xc045, 0x0055, 0x0066, 0xc076,
0xc089, 0x0099, 0x00aa, 0xc0ba, 0x00cc, 0xc0dc, 0xc0ef, 0x00ff,
0xc111, 0x0101, 0x0132, 0xc122, 0x0154, 0xc144, 0xc177, 0x0167,
0x0198, 0xc188, 0xc1bb, 0x01ab, 0xc1dd, 0x01cd, 0x01fe, 0xc1ee,
0xc221, 0x0231, 0x0202, 0xc212, 0x0264, 0xc274, 0xc247, 0x0257,
0x02a8, 0xc2b8, 0xc28b, 0x029b, 0xc2ed, 0x02fd, 0x02ce, 0xc2de,
0x0330, 0xc320, 0xc313, 0x0303, 0xc375, 0x0365, 0x0356, 0xc346,
0xc3b9, 0x03a9, 0x039a, 0xc38a, 0x03fc, 0xc3ec, 0xc3df, 0x03cf,
0xc441, 0x0451, 0x0462, 0xc472, 0x0404, 0xc414, 0xc427, 0x0437,
0x04c8, 0xc4d8, 0xc4eb, 0x04fb, 0xc48d, 0x049d, 0x04ae, 0xc4be,
0x0550, 0xc540, 0xc573, 0x0563, 0xc515, 0x0505, 0x0536, 0xc526,
0xc5d9, 0x05c9, 0x05fa, 0xc5ea, 0x059c, 0xc58c, 0xc5bf, 0x05af,
0x0660, 0xc670, 0xc643, 0x0653, 0xc625, 0x0635, 0x0606, 0xc616,
0xc6e9, 0x06f9, 0x06ca, 0xc6da, 0x06ac, 0xc6bc, 0xc68f, 0x069f,
0xc771, 0x0761, 0x0752, 0xc742, 0x0734, 0xc724, 0xc717, 0x0707,
0x07f8, 0xc7e8, 0xc7db, 0x07cb, 0xc7bd, 0x07ad, 0x079e, 0xc78e,
0xc881, 0x0891, 0x08a2, 0xc8b2, 0x08c4, 0xc8d4, 0xc8e7, 0x08f7,
0x0808, 0xc818, 0xc82b, 0x083b, 0xc84d, 0x085d, 0x086e, 0xc87e,
0x0990, 0xc980, 0xc9b3, 0x09a3, 0xc9d5, 0x09c5, 0x09f6, 0xc9e6,
0xc919, 0x0909, 0x093a, 0xc92a, 0x095c, 0xc94c, 0xc97f, 0x096f,
0x0aa0, 0xcab0, 0xca83, 0x0a93, 0xcae5, 0x0af5, 0x0ac6, 0xcad6,
0xca29, 0x0a39, 0x0a0a, 0xca1a, 0x0a6c, 0xca7c, 0xca4f, 0x0a5f,
0xcbb1, 0x0ba1, 0x0b92, 0xcb82, 0x0bf4, 0xcbe4, 0xcbd7, 0x0bc7,
0x0b38, 0xcb28, 0xcb1b, 0x0b0b, 0xcb7d, 0x0b6d, 0x0b5e, 0xcb4e,
0x0cc0, 0xccd0, 0xcce3, 0x0cf3, 0xcc85, 0x0c95, 0x0ca6, 0xccb6,
0xcc49, 0x0c59, 0x0c6a, 0xcc7a, 0x0c0c, 0xcc1c, 0xcc2f, 0x0c3f,
0xcdd1, 0x0dc1, 0x0df2, 0xcde2, 0x0d94, 0xcd84, 0xcdb7, 0x0da7,
0x0d58, 0xcd48, 0xcd7b, 0x0d6b, 0xcd1d, 0x0d0d, 0x0d3e, 0xcd2e,
0xcee1, 0x0ef1, 0x0ec2, 0xced2, 0x0ea4, 0xceb4, 0xce87, 0x0e97,
0x0e68, 0xce78, 0xce4b, 0x0e5b, 0xce2d, 0x0e3d, 0x0e0e, 0xce1e,
0x0ff0, 0xcfe0, 0xcfd3, 0x0fc3, 0xcfb5, 0x0fa5, 0x0f96, 0xcf86,
0xcf79, 0x0f69, 0x0f5a, 0xcf4a, 0x0f3c, 0xcf2c, 0xcf1f, 0x0f0f,
},
{
0x0000, 0xccc1, 0xd981, 0x1540, 0xf301, 0x3fc0, 0x2a80, 0xe641,
0xa601, 0x6ac0, 0x7f80, 0xb341, 0x5500, 0x99c1, 0x8c81, 0x4040,
0x0c01, 0xc0c0, 0xd580, 0x1941, 0xff00, 0x33c1, 0x2681, 0xea40,
0xaa00, 0x66c1, 0x7381, 0xbf40, 0x5901, 0x95c0, 0x8080, 0x4c41,
0x1802, 0xd4c3, 0xc183, 0x0d42, 0xeb03, 0x27c2, 0x3282, 0xfe43,
0xbe03, 0x72c2, 0x6782, 0xab43, 0x4d02, 0x81c3, 0x9483, 0x5842,
0x1403, 0xd8c2, 0xcd82, 0x0143, 0xe702, 0x2bc3, 0x3e83, 0xf242,
0xb202, 0x7ec3, 0x6b83, 0xa742, 0x4103, 0x8dc2, 0x9882, 0x5443,
0x3004, 0xfcc5, 0xe985, 0x2544, 0xc305, 0x0fc4, 0x1a84, 0xd645,
0x9605, 0x5ac4, 0x4f84, 0x8345, 0x6504, 0xa9c5, 0xbc85, 0x7044,
0x3c05, 0xf0c4, 0xe584, 0x2945, 0xcf04, 0x03c5, 0x1685, 0xda44,
0x9a04, 0x56c5, 0x4385, 0x8f44, 0x6905, 0xa5c4, 0xb084, 0x7c45,
0x2806, 0xe4c7, 0xf187, 0x3d46, 0xdb07, 0x17c6, 0x0286, 0xce47,
0x8e07, 0x42c6, 0x5786, 0x9b47, 0x7d06, 0xb1c7, 0xa487, 0x6846,
0x2407, 0xe8c6, 0xfd86, 0x3147, 0xd706, 0x1bc7, 0x0e87, 0xc246,
0x8206, 0x4ec7, 0x5b87, 0x9746, 0x7107, 0xbdc6, 0xa886, 0x6447,
0x6008, 0xacc9, 0xb989, 0x7548, 0x9309, 0x5fc8, 0x4a88, 0x8649,
0xc609, 0x0ac8, 0x1f88, 0xd349, 0x3508, 0xf9c9, 0xec89, 0x2048,
0x6c09, 0xa0c8, 0xb588, 0x7949, 0x9f08, 0x53c9, 0x4689, 0x8a48,
0xca08, 0x06c9, 0x1389, 0xdf48, 0x3909, 0xf5c8, 0xe088, 0x2c49,
0x780a, 0xb4cb, 0xa18b, 0x6d4a, 0x8b0b, 0x47ca, 0x528a, 0x9e4b,
0xde0b, 0x12ca, 0x078a, 0xcb4b, 0x2d0a, 0xe1cb, 0xf48b, 0x384a,
0x740b, 0xb8ca, 0xad8a, 0x614b, 0x870a, 0x4bcb, 0x5e8b, 0x924a,
0xd20a, 0x1ecb, 0x0b8b, 0xc74a, 0x210b, 0xedca, 0xf88a, 0x344b,
0x500c, 0x9ccd, 0x898d, 0x454c, 0xa30d, 0x6fcc, 0x7a8c, 0xb64d,
0xf60d, 0x3acc, 0x2f8c, 0xe34d, 0x050c, 0xc9cd, 0xdc8d, 0x104c,
0x5c0d, 0x90cc, 0x858c, 0x494d, 0xaf0c, 0x63cd, 0x768d, 0xba4c,
0xfa0c, 0x36cd, 0x238d, 0xef4c, 0x090d, 0xc5cc, 0xd08c, 0x1c4d,
0x480e, 0x84cf, 0x918f, 0x5d4e, 0xbb0f, 0x77ce, 0x628e, 0xae4f,
0xee0f, 0x22ce, 0x378e, 0xfb4f, 0x1d0e, 0xd1cf, 0xc48f, 0x084e,
0x440f, 0x88ce, 0x9d8e, 0x514f, 0xb70e, 0x7bcf, 0x6e8f, 0xa24e,
0xe20e, 0x2ecf, 0x3b8f, 0xf74e, 0x110f, 0xddce, 0xc88e, 0x044f,
},
};
public static ushort ComputeCrc(BinaryReader reader, long streamLength)
{
ushort crc = 0;
int pos = 0;
// High-speed 64 bit 8x256 lookup table implementation
while (streamLength - pos > 7)
{
ulong n = reader.ReadUInt64();
crc = (ushort)(Crc16Table[7, (int)(n & 0xff) ^ (crc & 0xff)] ^
Crc16Table[6, (int)((n >> 8) & 0xff) ^ ((crc >> 8) & 0xff)] ^
Crc16Table[5, (n >> 16) & 0xff] ^
Crc16Table[4, (n >> 24) & 0xff] ^
Crc16Table[3, (n >> 32) & 0xff] ^
Crc16Table[2, (n >> 40) & 0xff] ^
Crc16Table[1, (n >> 48) & 0xff] ^
Crc16Table[0, (n >> 56)]);
pos += 8;
}
// Process remaining bytes (max 7) using an 8 bit implementation
for (int i = pos; i < streamLength; i++)
{
byte next = reader.ReadByte();
crc = (ushort)(Crc16Table[0, (crc ^ next) & 0xff] ^ (crc >> 8));
}
return crc;
}
}
}