-3

我有一个等效的二进制值 1 110 11 我需要将突出显示的位设置为 0 101 00 ,我需要一个结果值为 1 101 11。如何设置这些位并保持不变。

4

2 回答 2

4

这应该有助于http://en.wikipedia.org/wiki/Bitwise_operations_in_C

如果您需要工作示例,请告诉我,但我鼓励您自己解决。

于 2013-02-20T17:58:26.417 回答
0
unsigned char my_byte = 0x3B; // 0b00111011

// clear the bits
my_byte &= 0xE3;

// set the bits
my_byte |= 0x14;

You'll find many people have many different preferences on how to write the 0xE3 and 0x14. Some like to shift bits, however ultimately this is the code that should be produced.

于 2013-02-20T18:22:19.217 回答