谜题,该怎么解决
谜题C/C++ codeCompute parity of word with a multiplyThe following method computes the parity of the
谜题
C/C++ codeCompute parity of word with a multiplyThe following method computes the parity of the 32-bit value in only 8 operations using a multiply. unsigned int v; // 32-bit word v ^= v >> 1; v ^= v >> 2; v = (v & 0x11111111U) * 0x11111111U; return (v >> 28) & 1;
求解.
[解决办法]看不懂英文
[解决办法]判断奇偶性?
[解决办法]下面的方法是只用8个操作用乘法运算计算32位值的奇偶性。
unsigned int v; //一个32位的无符号整形
v ^= v >> 1; // v右移一位,并与v异或,结果赋给v
v ^= v >> 2; // v右移三位,并与v异或,结果赋给v
v = (v & 0x11111111U) * 0x11111111U; //v 与 0x11111111然后乘0x11111111
return (v >> 28) & 1; //v右移28位,并与1(取最低位)
[解决办法]这个是算法的一部分,具体的算法我没做研究