Last active
April 14, 2021 15:00
-
-
Save cm3/773bdd3f7d0706a06ac56d554941fdf2 to your computer and use it in GitHub Desktop.
fnv1a_32 in JavaScript. see the history for a without-BigInt version
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 fnva = function(data){ | |
hval = BigInt(0x811c9dc5) | |
for (var i = 0; i < data.length; i++){ | |
hval ^= BigInt(data[i]) | |
hval = (hval * BigInt(0x01000193)) % BigInt(2**32) | |
} | |
return hval.toString(16).slice(-8).toUpperCase() | |
} | |
const encoder = new TextEncoder() | |
console.log(fnva(encoder.encode(process.argv[2]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment