Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:00:24+00:00 2026-05-26T01:00:24+00:00

I was looking through some of the .net source yesterday and saw several implementations

  • 0

I was looking through some of the .net source yesterday and saw several implementations of GetHashcode with something along the lines of this:

(i1 << 5) + i ^ i2

I understand what the code is doing and why. What I want to know is why they used (i1 << 5) + i instead of (i1 << 5) – i.

Most frameworks I’ve seen use -i because that’s equivalent to multiplying by 31 which is prime, but the Microsoft way is equivalent to multiplying by 33 which has 11 and 3 as factors and thus isn’t prime.

Is there a known justification for this? Any reasonable hypotheses?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:00:24+00:00Added an answer on May 26, 2026 at 1:00 am

    I asked the same question on math.stackexchange.com: Curious Properties of 33.

    The conjecture among mathematicians and the research I did on the topic leads me to believe that the answer is this:

    Okay, I found out why Microsoft uses 33. That’s called the Bernstein
    Hash. It turns out that 33 has some magical properties that produce a
    good distribution of hash codes and there’s very little theoretical
    knowledge as to why.

    Basically, in entropy and speed comparisons, Bernstein does well enough and is quite snappy. Dan Bernstein, the guy who came up with the constant 33, wasn’t able to explain what property of 33 produced such a good distribution of hashes.

    Several papers have been written comparing hash functions and have corroborated this finding without further explaining the benefit of using 33. Further, I couldn’t find why Java uses 31 instead. It appears to be a mathematical and programming mystery to date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some code (C# or VB.NET preferred) to iterate through all folders
I'm looking through some code for learning purposes. I'm working through this portion of
So I'm looking through some code, and I see this: class whatever { public:
I have been looking through some code on an open source project recently and
I was looking through some compiled coffee-script code, and I noticed something like the
I'm looking through my textbook and I'm a little confused about some of the
We are looking to run a large amount of data through some unit tests.
I'm running some code through FxCop and am currently looking at clearing all of
I'm looking for some free software to let me browse through the files/records in
I am looking though some source code from a third party and am repeatedly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.