All problems
FNV-1a Hash
Problem
Compute the 32-bit FNV-1a hash of a string: start from the offset basis 2166136261, XOR each character code into the hash and multiply by the prime 16777619, keeping only the low 32 bits.
All arithmetic is unsigned and wraps modulo 2 to the 32nd power. The empty string hashes to the offset basis.
Hint
XOR before the multiply is what distinguishes FNV-1a from FNV-1.
Test cases
case 1
in: [""]
expected: 2166136261
case 2
in: ["a"]
expected: 3826002220
case 3
in: ["foobar"]
expected: 3214735720
case 4
in: ["hello"]
expected: 1335831723
case 5
in: ["abc"]
expected: 440920331
Starter codePython
def fnv1a_hash(data):
# Your code here
pass5 test cases · run your code against them in the editor