将十六进制转化为点分十进制,如0xffffffff为255.255.255.255

#include <stdio.h>
int main()
{
    int src=0xffffffff;
    printf("请输入十六进制地址:");
    while(scanf("%x",&src)!=EOF)
    {
        int res[4];
        int times=4;
        while(times>0)
        {
            int temp=0x000000ff;
            temp=temp&src;            
            res[times-1]=temp;
            src=src>>8;
            times--;
        }
        for(times=0;times<4;times++)
        {
            printf("%d",res[times]);
            if(times<3) {putchar('.');}
            else {putchar('\n');}
        }
        printf("请输入十六进制地址:");
    }
    return 0;
}

 

posted on 2014-03-03 15:58  简单的信仰  阅读(1285)  评论(0编辑  收藏  举报