c - C中2个字节代表3个整数

标签 c

我有两个字节,8 位八位字节,应该读作:[3 位][4 位][3 位]。

例子:

unsigned char octet1 = 0b11111111;  // binary values
unsigned char octet2 = 0b00000011;

作为整数:[7][15][7]。

任何人都可以提示我从哪里开始?

最佳答案

在一种pseudocode

octet1 = 0b11111111
octet2 = 0b00000011
word = octet1 | octet2<<8
n1 = word & 0b111
n2 = word>>3 & 0b1111
n3 = word>>7 & 0b111

关于c - C中2个字节代表3个整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4096091/

相关文章:

c - 模糊图像矩阵时出现分割错误。 [C]

c - C语言的反射(reflection)?

c - 像 "GLenum GlewInitResult = glewInit();"这样的声明(?)是做什么的?

c - int a=1, b=a++;调用未定义的行为?

c - 引发异常的 Windows API

c - semget : how to avoid concurrent access to semaphore group on its creating/initialization?

c - 初始化作为结构数组索引的 C 结构

c - 关于c语言编程中的指针

c - C 格式的 Typedef 和 enum 以及优点

c - unix管道(|)和我们在c中使用 "pipe(int pipefd[2])"创建的管道一样吗?