Partager via


1.3.9.1 Non-Null-Terminated Unicode String to Unsigned Integer Hash

Given a non-null-terminated Unicode string and the length of the string, a 4-byte unsigned integer hash value can be obtained by performing the following algorithm:

1. Given an input string and length of the input string (cch).

2. Set a 4-byte unsigned integer value nHash equal to 0x00000000.

3. For each character from position 0 to the end of the input string perform the following steps.

Example:

          for (i=0; ich<cch; ++ich)
             nHash = (nHash<<5) + nHash + inputString[ich];

1. Set nHash, equal to itself bitwise shifted left 5 times, added unto itself, and then added to the value of the character of input string at ich.

2. nHash will be stored and used again in the next iteration of the loop until the last character of input string.

4. The result of the algorithm is the value nHash.