C语言输出int型整数的二进制值(使用结构体位域)
程序员文章站
2022-07-14 23:09:47
...
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
struct bits//结构体
{
unsigned char bit1 : 1;//位域
unsigned char bit2 : 1;
unsigned char bit3 : 1;
unsigned char bit4 : 1;
unsigned char bit5 : 1;
unsigned char bit6 : 1;
unsigned char bit7 : 1;
unsigned char bit8 : 1;
};
int main(int argc, char *argv[])
{
int num;
scanf("%d", &num);
struct bits *p = #
int i = 4;
while (i--)//输出二进制
{
printf("%d%d%d%d %d%d%d%d ", (p + i)->bit8, (p + i)->bit7, (p + i)->bit6, (p + i)->bit5, (p + i)->bit4, (p + i)->bit3, (p + i)->bit2, (p + i)->bit1);
}
system("pause");
return 0;
}
下一篇: 好好学习scheme