位扩展

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值