#include <stdio.h>
typedef struct uuc
{
unsigned char c1:1;
unsigned char c2:1;
unsigned char c3:1;
unsigned char c4:1;
unsigned char c5:1;
unsigned char c6:1;
unsigned char c7:1;
unsigned char c8:1;
} Uuc;
typedef union
{
unsigned char unc;
Uuc uuc;
}UUc;
typedef struct unc
{
unsigned int n1:4;
unsigned int n2:4;
unsigned int n3:4;
unsigned int n4:4;
unsigned int n5:4;
unsigned int n6:4;
unsigned int n7:4;
unsigned int n8:4;
} Unc;
typedef union
{
unsigned int unn;
Unc uun;
}UNc;
void output_UUc(UUc uc)
{
printf("%d",uc.uuc.c8);
printf("%d",uc.uuc.c7);
printf("%d",uc.uuc.c6);
printf("%d",uc.uuc.c5);
printf("%d",uc.uuc.c4);
printf("%d",uc.uuc.c3);
printf("%d",uc.uuc.c2);
printf("%d",uc.uuc.c1);
puts("/n");
}
void output_UNc(UNc un)
{
printf("%d",un.uun.n8);
printf("%d",un.uun.n7);
printf("%d",un.uun.n6);
printf("%d",un.uun.n5);
printf("%d",un.uun.n4);
printf("%d",un.uun.n3);
printf("%d",un.uun.n2);
printf("%d",un.uun.n1);
puts("/n");
}
unsigned int expend(unsigned char c)
{
UUc uc;
UNc un;
uc.unc=c;
un.unn=0;
un.uun.n1=uc.uuc.c1?0xf:0x0;//1扩展为1111,0扩展为0000
un.uun.n2=uc.uuc.c2?0xf:0x0;
un.uun.n3=uc.uuc.c3?0xf:0x0;
un.uun.n4=uc.uuc.c4?0xf:0x0;
un.uun.n5=uc.uuc.c5?0xf:0x0;
un.uun.n6=uc.uuc.c6?0xf:0x0;
un.uun.n7=uc.uuc.c7?0xf:0x0;
un.uun.n8=uc.uuc.c8?0xf:0x0;
output_UUc(uc);
output_UNc(un);
return un.unn;
}
int main(void)
{
unsigned char c=0x38;
printf("%x/n",c);
printf("%x/n",expend(c));
getchar();
return 0;
}