Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个 4 位十六进制值 A、B,我想用 A 的 MSD 和 B 的 LSD 创建一个 8 位的值:
这是我的尝试:
uint8_t X = (A << 4) & (B);
我得到一个值,但不确定它是否正确。
这是一个正确的方法吗?
它需要是:
uint8_t X = (A << 4) | (B); ^^^
这是因为您需要将两个值按位或( |) 组合在一起,而不是按位与( &)。
|
&
有关使用按位 OR 组合 nybble 值的类似示例,请参见您之前问题的答案。