Last active
February 27, 2017 23:12
-
-
Save Hugoberry/a35af475c658545d8b97027d1b771c26 to your computer and use it in GitHub Desktop.
Precomputin the CRC32 lookup table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calculateCRClookup = (divident)=> | |
let | |
// move divident byte into MSB of 32Bit CRC | |
curByte = Number.BitwiseShiftLeft(divident,24) | |
in | |
List.Accumulate({0..7}, | |
curByte, | |
(_curByte,_)=> | |
let | |
// if MSB set, shift left and XOR with polynomial = 0x4C11DB7 | |
then_clause = Number.BitwiseXor(Number.BitwiseShiftLeft(_curByte,1),0x4C11DB7), | |
// else shift one bit left | |
else_clause = Number.BitwiseShiftLeft(_curByte,1) | |
in //if MSB set | |
if Number.BitwiseAnd(_curByte,0x80000000)<>0 then then_clause else else_clause ), | |
// precompute CRC32 lookup table | |
CRC_table = List.Generate(()=>[count=0,crc=0], each [count]<256, // iterate over all possible input byte values 0-255 | |
each [count = [count]+1, crc = calculateCRClookup(count) ], each [crc]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment