Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement