title: Rotating Hash for 16 bit
body: <p><a href="http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx" rel="nofollow">This site</a> gives description of rotating hash as follows.</p>
  
  <pre><code>unsigned rot_hash ( void *key, int len )
  {
      unsigned char *p = key;
      unsigned h = 0;
      int i;
  
      for ( i = 0; i &lt; len; i++ )
          h = ( h &lt;&lt; 4 ) ^ ( h &gt;&gt; 28 ) ^ p[i];
  
     return h;
  } 
  </code></pre>
  
  <p>The returned value is 32 bit here. However, I want to return a 16 bit hash value. For that purpose, is it correct to assign <code>h</code> as follows in the loop? Consider <code>h</code> to be declared as a 16 bit integer here.</p>
  
  <pre><code>for ( i = 0; i &lt; len; i++ )
            h = ( h &lt;&lt; 4 ) ^ ( h &gt;&gt; 12 ) ^ p[i];
  </code></pre>