Last active
September 23, 2019 11:38
-
-
Save mildsunrise/632bb4db2a98f563fb48c82710fc2290 to your computer and use it in GitHub Desktop.
CRC32
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
const table = new Int32Array(256).map((_,n) => [...Array(8)] | |
.reduce(c => (c>>>1) ^ ((c&1) * 0xEDB88320), n)) | |
const fn = (C, b) => (C>>>8) ^ table[(C^b) & 0xFF] | |
const crc = (x, seed) => ~x.reduce(fn, ~seed) | |
// Example: | |
crc( Buffer.from('Hello') ) === 0xF7D18982 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment