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);


How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?