关于取出字符位的位域操作技巧

typedef struct _aaa
{
unsigned char a1 : 1;
unsigned char a2 : 1;
unsigned char a3 : 1;
unsigned char a4 : 1;
unsigned char a5 : 1;
unsigned char a6 : 1;
unsigned char a7 : 1;
unsigned char a8 : 1;
}aaa;
int main(int argc, _TCHAR* argv[])
{
printf("hello ");
unsigned char b;
b = 60;
printf("%d,%d,%d,%d,%d,%d,%d,%d", ((aaa *)&b)->a8, ((aaa *)&b)->a7, ((aaa *)&b)->a6, ((aaa *)&b)->a5, ((aaa *)&b)->a4, ((aaa *)&b)->a3, ((aaa *)&b)->a2, ((aaa *)&b)->a1);
return 0;
}
阅读更多
文章标签: C++ 位域
个人分类: c/c++
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭