admin 管理员组

文章数量: 1086019


2024年12月22日发(作者:php金职位)

C语言十进制数转化为十六进制数

#include

#include

#include

void reversestr(char*source,char target[],unsigned int length);

void tohex(unsigned long num,char*hexStr);

int main()

{

char hexStr[16];

int num;

printf("请输入一个十进制数:n");

scanf("%d",&num);

tohex(num,hexStr);

printf("转换成的十六进制为:%sn",hexStr);

system("pause");

}

void reversestr(char*source,char target[],unsigned int length)

{

unsigned int i;

for(i=0;i

target[i]=source[length-1-i];

target[i]=0;

}

void tohex(unsigned long num,char*hexStr)

{

unsigned long n=num;

char hextable[]="ABCDEF";

char temphex[16],hex[16];

unsigned long int i=0;

while(n)

{

temphex[i++]=hextable[n];

n/=16;

}

temphex[i]=0;

reversestr(temphex,hex,i);

strcpy(hexStr,hex);

}


本文标签: 职位 转化 作者 C语言