所以现在我有这个
unsigned char getlsbs(unsigned char *p){
int r;
unsigned char newByte, temp;
newByte = 0;
for(r = 0; r < 8; r++){
temp = p[r];
temp &= -temp; // Gets the LSB of p[r]
((newByte & (1 << r)) >> r) |= temp; //This line does not work
}
return newByte;
}
对于不起作用的行,我试图将 newByte 的第 rth int 设置为 LSD,这样我就可以将 00000000 变成类似 10100001 的值,任何帮助将不胜感激
最佳答案
您不能分配给表达式。为了简化问题:a + 1 = b
不起作用。将其重写为 a = b - 1
。
我会这样做:
for(r = 0; r < 8; r++){
newByte |= (p[r] & 1) >> r;
}
关于c - 获取数组中每个 int 的 LSB 并将它们组合起来创建一个字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33771938/