Hash functional or algorithm to get generate 4 character Hash value.
Original question is – How to generate 4 character hash value from the given string using c#?
You can use unsigned Integer to generate a hash value. Here we want 4 characters so I take the example of UInt16 to get 4 characters. You can also use Uint32 and Uint64 to get more character in the hash value.
public static string getHashValue(string str) { UInt16 hashedValue = 0x1234; //You can change the value for (int i = 0; i < str.Length; i++) { hashedValue += (byte)str[i]; hashedValue *= 0x1111; //You can change the value } return String.Format("{0:X}",hashedValue); }