案例:C语言位域-证明高位在高字节,低位在低字节
作者:互联网
注:参考自尹成CPP课程
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
struct BitType
{
unsigned char ch1 : 1;
unsigned char ch2 : 1;
unsigned char ch3 : 1;
unsigned char ch4 : 1;
unsigned char ch5 : 1;
unsigned char ch6 : 1;
unsigned char ch7 : 1;
unsigned char ch8 : 1;
};
int main()
{
//int num; scanf("%d", &num);
double num; scanf("%lf", &num);
int len = sizeof(num);
struct BitType* pb = (struct BitType*)#
while (len--)
{
printf("%d%d%d%d %d%d%d%d\n",
(pb + len)->ch8,
(pb + len)->ch7,
(pb + len)->ch6,
(pb + len)->ch5,
(pb + len)->ch4,
(pb + len)->ch3,
(pb + len)->ch2,
(pb + len)->ch1);
}
return 0;
}
流浪DDing
发布了23 篇原创文章 · 获赞 1 · 访问量 471
私信
关注
标签:char,d%,unsigned,len,C语言,pb,num,低字节,位域 来源: https://blog.csdn.net/weixin_41188593/article/details/104520958