- 论坛徽章:
- 0
|
#define PB(X) printf((X)?"1":"0")
#define UI unsigned int
struct byte
{
UI a0:1;
UI a1:1;
UI a2:1;
UI a3:1;
UI a4:1;
UI a5:1;
UI a6;
UI a7;
};
union bits{char ch;struct byte bit;};
void decode(union bits c);
void main()
{
char c;
union bits asc;
for(c='A';c<'C';c++)
{
asc.ch=c;
printf("%o:",c);
decode(asc);
}
}
void decode(union bits b)
{
PB(b.bit.a7);
PB(b.bit.a6);
PB(b.bit.a5);
PB(b.bit.a4);
PB(b.bit.a3);
PB(b.bit.a2);
PB(b.bit.a1);
PB(b.bit.a0);
printf("\n");
}
答案:101:11000001
102:11000010 |
|