Alex Rivera | Logout

Fixed Length numeric hash code from variable length string in c#

Asked 2009-02-13T23:57:56.830
18

I need to store fixed-length (up to 8 digits) numbers produced from a variable length strings. The hash need not be unique. It just needs to change when input string changes. Is there a hash function in .Net that does this?

Thanks
Kishore.

Edit
Report

1 Answer

6

Simple approach (note that this is platform-dependent):

int shorthash = "test".GetHashCode() % 100000000; // 8 zeros
if (shorthash < 0) shorthash *= -1;
answered 2009-02-14T00:04:04.007

Your Answer