在C波浪运营商 [英] The tilde operator in C
本文介绍了在C波浪运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我见过的ELF散列算法使用了波浪线运营商,和我很好奇它做什么。 (在code是永恒困惑 。)
无符号elf_hash(无效*键,INT LEN)
{
无符号的char * p =键;
无符号H = 0,克;
INT I; 对于(i = 0; I< LEN,我++){
H =(H&下; 4;)+ P [I];
G =的H& 0xf0000000L; 如果(G!= 0)
H ^ = g取代;> 24; 的H& =〜克;
} 返回H;
}
解决方案
的〜
操作符是按位的 NOT 的,它反转位二进制数:
011100 NOT
= 100011
I've seen the tilde operator used in the ELF hashing algorithm, and I'm curious what it does. (The code is from 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;
}
解决方案
The ~
operator is bitwise NOT, it inverts the bits in a binary number:
NOT 011100
= 100011
这篇关于在C波浪运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文