c语言定义100个位域,搞懂这个C程序,C语言中的位域、位运算你就理解的差不多了。。。...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/*程序注解:位域的定义和使用,以及位操作符的运算*/

#include "stdio.h"

/*该数据结构供占用6个字节即6*8=48位*/

struct data

{

unsigned a:8;

unsigned b:1;

unsigned :0;

unsigned c:7;

unsigned d:2;

unsigned :2;

unsigned e:4;

unsigned f:3;

unsigned g:5;

unsigned h:6;

}bit,*pbit;

main()

{

bit.a=255;

bit.b=1;

bit.c=127;

bit.d=3;

bit.e=15;

bit.f=7;

bit.g=31;

bit.h=63;

printf("Use structure name output--->>>\n");

printf("a=%d\n",bit.a);

printf("\nb=%d\n",bit.b);

printf("c=%d\n",bit.c);

printf("\nd=%d\n",bit.d);

printf("e=%d\n",bit.e);

printf("\nf=%d\n",bit.f);

printf("g=%d\n",bit.g);

printf("\nh=%d\n",bit.h);

printf("Use pointer output--->>>\n");

pbit=&bit;

pbit->a+=1;

pbit->b=~pbit->b;

pbit->c&=3;

pbit->d|=0;

pbit->e^=10;

pbit->f<<=2;

pbit->g>>=2;

pbit->h+=2;

printf("a=%d\n",pbit->a);

printf("b=%d\n",pbit->b);

printf("c=%d\n",pbit->c);

printf("d=%d\n",pbit->d);

printf("e=%d\n",pbit->e);

printf("f=%d\n",pbit->f);

printf("g=%d\n",pbit->g);

printf("h=%d\n",pbit->h);

getch();

}

/* 输出结果如下:

Use structure name output--->>>

a=255

b=1

c=127

d=3

e=15

f=7

g=31

h=63

Use pointer output--->>>

a=0

b=0

c=3

d=3

e=5

f=4

g=7

h=1

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值