【发布时间】:2019-12-03 14:26:34
【问题描述】:
我的目标是编写一个函数,它接收一个无符号字符作为输入,并返回一个修改后的无符号字符作为输出。
应该修改 char,使其前三位设置为零,其余的保持不变。下面编写的示例函数。
非常感谢任何帮助。抱歉,这个问题有些不完整,这是我能给出的最准确的描述。
unsigned char Changebits(unsigned char b)
{
//set the first three bits of the input to zeros (for example 10110111 -> 00010111)
return //insert the modified unsigned char here
}
【问题讨论】:
-
b & 0x1f /*0b00011111*/ -
return (b & 0x1Fu) -
全错了,如果你想将 unsigned char 的 3 个第一位 归零,正确的掩码是
UCHAR_MAX >> 3:D