在Windows中使用C / C半字节(4位变量)++ [英] Using nibbles (4 bits variables) in windows C/C++
本文介绍了在Windows中使用C / C半字节(4位变量)++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编程的网络标题和大量的协议,使用4位字段。是否有一个方便的类型,我可以用它来重新present这些信息?
I'm programming network headers and a lot of protocols use 4 bits fields. Is there a convenient type I can use to represent this information?
我发现的最小的类型是一个字节。然后,我必须使用大量的二进制运算的引用变量里面只有几个位。
The smallest type I've found is a BYTE. I must then use a lot of binary operations to reference only a few bits inside that variable.
推荐答案
由于内存字节寻址,你不能解决大于单字节较小的任何单位。但是,您可以建立结构
要通过网络发送和使用的 位域 是这样的:
Since the memory is byte-addressed, you can't address any unit smaller than a single byte. However, you can build the struct
you want to send over the network and use bit fields like this:
struct A {
unsigned int nibble1 : 4;
unsigned int nibble2 : 4;
};
这篇关于在Windows中使用C / C半字节(4位变量)++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文