I'm looking for a way to make a 16bit ID out of approx 100 bits of data. The solution should be easy to implement, or should already be implemented in c++, should be quick to evaluate, and most importantly the values of the ID should be uniformly distributed, which is to say that one value should not have a higher chance to be taken than another.
closed as off topic by rook, Ninefingers, Rory Alsop♦ Jun 19 '12 at 19:09
Questions on Information Security Stack Exchange are expected to relate to Information security within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.
As mentioned in the question Rook linked, 16bits is very very weak, reducing 100bits to 16 leads to ~6 possible collisions per hash.
Are you sure you need a hash for that ? 16bits is enough to be stored in an integer and could simply be incremented if you just need a way to identify an object (limited to 65536).
If nevertheless you want to use an hash function, you could try to use something very simple such as Pearson hashing that will produce a 8bit hash.
I quote Wikipedia, the advantages of this function are :
The adaptation to 16bits shouldn't be too hard. For example, this page gives an example of adaptation but I think the author forget to change the size of the table to 65535, the code would be :