zoukankan      html  css  js  c++  java
  • 十进制转十六进制

    代码:

    #include <stdio.h>
    #include <stdlib.h>
    
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    
    int main(int argc, char *argv[]) {
        int n;
        int count=0;
        int temp;
        int i;
        char num[10000];
        scanf("%d",&n);
        do{
            temp = n%16;
            if(temp>9){
                switch(temp){
                    case 10: num[count]='A'; break;
                    case 11: num[count]='B'; break;
                    case 12: num[count]='C'; break;
                    case 13: num[count]='D'; break;
                    case 14: num[count]='E'; break;
                    case 15: num[count]='F'; break;
                }
                count++;
                
            }else{
                num[count]=n%16+'0';
                count++;
            }
            n = n/16;
            
            
        }while(n!=0);
        
        for(i=count-1;i>=0;i--){
            printf("%c",num[i]);
        }
        return 0;
    }

    运行结果:

  • 相关阅读:
    MATLAB accumarray
    函数rand,randn,randi
    bsxfun
    sub2ind函数
    MAX
    & 和 &&
    matlab函数int2str, num2str, str2num
    ASCII对照表
    STM32的ADC配置
    单节锂电池基本知识
  • 原文地址:https://www.cnblogs.com/ZZG-GANGAN/p/14671997.html
Copyright © 2011-2022 走看看