其他分享
首页 > 其他分享> > C语言:结构体_位操作

C语言:结构体_位操作

作者:互联网

源码:

#include <stdio.h>
 
struct test_tag
{
	unsigned int a : 1;
	unsigned int b : 1;
	unsigned int c : 1;
	unsigned int d : 1;
	unsigned int e : 1;
	unsigned int f : 1;
	unsigned int h : 1;
	unsigned int i : 1;
	unsigned int j : 24;
}test;
 
int main() 
{
	int i;
	
	test.a=0;
	test.b=0;
	test.c=1;
	test.d=1;
	test.e=1;
	test.f=1;
	test.h=1;
	test.i=1;
	test.j=0;
	
	i=*((int *)&test);
	
	printf("%d \n", i);
	
	return 0;
}



运行结果:

root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/4_file# gcc -o test test.c 
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/4_file# ./test
252 
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/4_file#

参考链接: https://blog.csdn.net/daniel_ustc/article/details/8103398

标签:位操作,hgfs,Ubuntu12.04,int,mnt,unsigned,C语言,test,结构
来源: https://blog.csdn.net/weixin_38184741/article/details/89886852