我正在从微控制器读取两个寄存器。一个有 4 位 MSB(前 4 位有一些其他的东西)和另一个 8 位 LSB。我想将其转换为一个 12 位 uint(准确地说是 16 位)。到目前为止,我是这样的:
UINT16 x;
UINT8 RegValue = 0;
UINT8 RegValue1 = 0;
ReadRegister(Register01, &RegValue1);
ReadRegister(Register02, &RegValue2);
x = RegValue1 & 0x000F;
x = x << 8;
x = x | RegValue2 & 0x00FF;
有没有更好的方法来做到这一点?
/ *更准确地说,ReadRegister 是与另一个 ADC 的 I2C 通信。Register01 和 Register02 是不同的地址。RegValue1 是 8 位,但只需要 4 个 LSB 并连接到 RegValue(RegValue1 的 4-LSB 和 RegValue 的所有 8 位)。*/