little endian에서의 Structure 2진수 출력
2018. 3. 27. 23:23 in 프로그래밍 세계/Coding Skill _ 비트연산

#include <stdio.h>
typedef struct {
char a;
char b;
int c;
} NODE_t;
void printBinary(char i)
{
int j;
for (j = 7; j >= 0; j--)
{
printf("%d", (i >> j) & 1);
}
printf(" ");
}
void run5()
{
char *ptr;
int idx;
NODE_t node;
node.a = 0x65;
node.b = 0xf0;
node.c = 0x01020304;
ptr = (char *)&node;
for (idx = 0; idx < sizeof(NODE_t); idx++)
{
printBinary(*ptr++);
}
}