位域-得到任何类型二进制显示
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
typedef struct {// 1byte = 8bit 按照字节来解析
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;
}Byte;
void main() {
int data = 55;
int length = sizeof(data);
Byte *byte = &data;
while (length--)
{
printf("%d%d%d%d %d%d%d%d ",
//高位
(byte + length)->bit8,
(byte + length)->bit7,
(byte + length)->bit6,
(byte + length)->bit5,
//低位
(byte + length)->bit4,
(byte + length)->bit3,
(byte + length)->bit2,
(byte + length)->bit1);
}
printf("\n");
system("pause");
}