title: The tilde operator in C
body: <p>I've seen the tilde operator used in the ELF hashing algorithm, and I'm curious what it does. (The code is <a href="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx">from Eternally Confused</a>.)</p>
  
  <pre><code>unsigned elf_hash ( void *key, int len )
  {
    unsigned char *p = key;
    unsigned h = 0, g;
    int i;
  
    for ( i = 0; i &lt; len; i++ ) {
      h = ( h &lt;&lt; 4 ) + p[i];
      g = h &amp; 0xf0000000L;
  
      if ( g != 0 )
        h ^= g &gt;&gt; 24;
  
      h &amp;= ~g;
    }
  
    return h;
  }
  </code></pre>