我有三个 32 位整数 a、b、c。我想制作 a=(b 的第 23 位) xor (c 的第 4 位) 的第 10 位而不干扰 a 的其他位。如何用 C 编程语言做到这一点?a 也可以为零。在这种情况下,我认为 a= 00...0, 32 个零。
如何在 C 中更改 32 位整数的一位
计算科学
C
2021-11-29 19:25:14
1个回答
// 10th bit of a=(23 rd bit of b) xor (4th bit of c)
if( a )
{ // skip if 'a' already all 0's
int tempB = (b>>23)&0x01; // extract bit 23 and place on bit 0
int tempC = (c>>4)&0x01; // extract bit 4 and place in bit 0
int tempXOR = (tempB^tempC)&0x01;// XOR the bits
a &= ~(1<<10); // clear bit 10
a |= (tempXOR<<10); // place result of XOR into bit 10 of a
}
其它你可能感兴趣的问题