In an assignment involving cyclic shift hash codes, the instructions include the following code:

int hashCode(const char* p, int len) 
{ unsigned int h = 0;
  for (int i = 0; i < len; i++)
  { h = (h << 5)|(h >> 27);        
    h += (unsigned int)p[i];      
  }
  return h;
}

What do the >> and << in line 4 mean?

Recommended Answers

Here is a good explanation of left shift (<<) and right shift (>>)
http://irc.essex.ac.uk/www.iota-six.co.uk/c/e5_bitwise_shift_operators.asp

Dave

Jump to Post

All 2 Replies

daviddoria,

Thanks a lot! Your link was really helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.