level 1
-3源码=1······011
反码=1·······100
补码=1·······101
补码(2)=0·······010 也就是=2
3的源码=0·······011
异或的不爽补码二和3的源码进行吗这样不是最后的答案是1,吗,但是答案不是。我不知道哪里错了,请大神指教
2013年08月05日 00点08分
1
level 5
<?php
function getHash(/* string */$str, $M = 249997) {
$hash = 0;
for($i = 0; isset($str[$i]); $i++) {
$hash = ($hash << 4) + ord($str[$i]);
$hash &= 0x7fffffff;
printf("hash=0x%08x\n", $hash);
$x = $hash & 0xf0000000;
if ($x) {
$hash ^= ($x >> 24);
$hash &= ~$x;
}
}
return $hash % $M;
}
$s = "192.168.0.0:111";
$hash = getHash($s);
printf("hash=%08x\n", $hash);
2021年05月08日 11点05分
2
level 5
#include <stdio.h>
int getHash(const char *str) {
int hash = 0, x = 0;
int i;
for (i = 0; str[i]!='\0'; i++) {
hash = (hash << 4) + str[i];
printf("0x%08x\n", hash);
x = hash & 0xf0000000;
if (0 != x) {
hash ^= (x >> 24);
hash &= ~x;
}
}
return hash % 249997;
}
int main(int argc, char *argv[]) {
const char str[] = "192.168.0.0:111";
int hash = getHash(str);
printf("%08x\n", hash);
return 0;
}
2021年05月08日 11点05分
3