其思想是将各种无线电发射模块与模拟线圈发射信号进行比较.
因此,需要发送单比特与arduino无线电发射模块进行比较。
我已经尝试过包含位集并定义如下内容:
std::bitset<1> p(1);但它仍然有4字节大小。
有什么办法来声明一点吗?
发布于 2019-08-01 18:04:12
不,您不能声明单个位。仅以8的倍数表示(也称为字节)。在C++中,char类型的变量大小为1字节。如果您想传输/比较一个位序列,可以使用_char_s或一个_char_s数组。
char single_byte = 32; // same as 0010 0000
char some_bytes[3] = {8, 254, 1}; // same as 0000 1000 1111 1110 0000 0001要检查是否将位设置在特定位置,可以使用按位运算符(如& )。
// example:
// check if the second bit of the second byte in some_bytes is set
char filter = 64; // 0100 0000
if (some_bytes[1] & filter) // 1111 1110 & 0100 000 = 0100 0000
// returns truehttps://stackoverflow.com/questions/57313478
复制相似问题