我已经看到了ELF哈希算法中使用的波浪号运算符,我很好奇它的作用.(代码来自Eternally Confused.)
unsigned elf_hash ( void *key, int len )
{
unsigned char *p = key;
unsigned h = 0, g;
int i;
for ( i = 0; i < len; i++ ) {
h = ( h << 4 ) + p[i];
g = h & 0xf0000000L;
if ( g != 0 )
h ^= g >> 24;
h &= ~g;
}
return h;
}
Run Code Online (Sandbox Code Playgroud)
GWW*_*GWW 116
该~
操作是按位NOT,它反转位二进制数:
NOT 011100
= 100011
Run Code Online (Sandbox Code Playgroud)
dle*_*lev 41
~
是按位NOT运算符.它反转操作数的位.
例如,如果您有:
char b = 0xF0; /* Bits are 11110000 */
char c = ~b; /* Bits are 00001111 */
Run Code Online (Sandbox Code Playgroud)