zoukankan      html  css  js  c++  java
  • 如何将16进制字符串转化成10进制输出

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h >
    int zh(char s[])
    {
        int i,m,temp=0,n;
        m=strlen(s);//十六进制是按字符串传进来的,所以要获得他的长度
        for(i=0;i<m;i++)
        {
            if(s[i]>='A'&&s[i]<='F')//十六进制还要判断他是不是在A-F或者a-f之间a=10。。
             n=s[i]-'A'+10;
            else if(s[i]>='a'&&s[i]<='f')
             n=s[i]-'a'+10;
             else n=s[i]-'0';
            temp=temp*16+n;
        }
        return temp;
    }
    int main()
    {
        char s[10];
        gets(s);
        int n=zh(s);
        printf("%d
    ",n);
        return 0;
    }
    

      

    输入:

    07e1

    输出:

    2017

  • 相关阅读:
    菜根谭#317
    菜根谭#316
    菜根谭#315
    菜根谭#314
    菜根谭#313
    菜根谭#312
    菜根谭#311
    菜根谭#310
    菜根谭#309
    Matlab xpC启动盘
  • 原文地址:https://www.cnblogs.com/secondtononewe/p/7069967.html
Copyright © 2011-2022 走看看