如何与字符类型的位域工作的? [英] How does a bit field work with character types?
本文介绍了如何与字符类型的位域工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct stats
{
char top : 1;
char bottom : 1;
char side : 2;
} MyStat;
我已经看到了这个整数格式,但怎么做上面的char位域工作的,什么是它重新present?
I have seen this format with integers but how does the above char bit field work and what does it represent?
感谢您。
推荐答案
字符位字段相同的方式工作,为int,就在基本类型是8位的,而不是32位。所以,你会得到一个结构统计,其中有1个字节的大小,3成员变量,一共有4位占据。
Char bit fields work in the same way as int, just the base type is 8-bit wide, not 32-bit. So you'd get a struct stats, which has the size of 1 byte, and 3 member variables, occupying a total of 4 bits.
这篇关于如何与字符类型的位域工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文