If you need a general purpose string hash function then check out the djb2 hashing on this site:
http://www.cse.yorku.ca/~oz/hash.html[
^]. If I remember right this general purpose string hash function is used in java as well. But in the comments of the previous solution the guys already pointed out: char[400] is already a 400*8 bit number, and you can not generate a unique number represented in less bits for each member of the previous much bigger set. This is where you have to make sure that the hash function you are using doesn't have a lot of collisions on the set of input data you are usually using. If you don't exactly know what is the content of your input strings, then the general purpose djb2 hash will be nice for you. But for example if you know that your strings will contain the textual representation of numbers between 0 and 2^32, then a function that converts the string to integer is a perfect hash function (without collisions), but to achieve this we need to know something about the input data (like with compression algorithms). Hashing and compression have a lot in common as a previous poster pointed out. Hashing can improve the performance of some simple data structures like set and map where some operations include searching for a key. Searching is usually done by performing binary halving on a list of sorted items, but with hashing you can achieve much better performance if your hash function doesn't have a lot of collisions (in english, you don't have a lot of items with the same hash).