Hash 32bit int to 16bit int?
Posted
by dkamins
on Stack Overflow
See other posts from Stack Overflow
or by dkamins
Published on 2010-06-17T00:32:17Z
Indexed on
2010/06/17
0:42 UTC
Read the original article
Hit count: 358
What are some simple ways to hash a 32-bit integer (e.g. IP address, e.g. Unix time_t, etc.) down to a 16-bit integer?
E.g. hash_32b_to_16b(0x12345678)
might return 0xABCD
.
Let's start with this as a horrible but functional example solution:
function hash_32b_to_16b(val32b) {
return val32b % 0xffff;
}
Question is specifically about JavaScript, but feel free to add any language-neutral solutions, preferably without using library functions.
Simple = good. Wacky+obfuscated = amusing.
© Stack Overflow or respective owner