C语言高手来帮帮忙,要求程序将一个十进制转换成十六进制整数,用数组分别存放十六进制的字符再输出
2个回答
展开全部
#include<stdio.h>
#include<math.h>
#define BUFF_SIZE 100
char Hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void Covert2HexStr(int num, int buff_size, char * buff)
{
int t;
int count = (int)(log(num)/log(16));
buff[count+1]=0;
for(;count >=0;--count)
{
t = num % 16;
num /= 16;
*(buff+count) = *(Hex+t);
}
}
int main()
{
char buf[BUFF_SIZE];
int a=0x06FE1234;
Covert2HexStr(a,BUFF_SIZE, buf);
printf("%s\n",buf);
}
/**
输出:6FE1234
**/
#include<math.h>
#define BUFF_SIZE 100
char Hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void Covert2HexStr(int num, int buff_size, char * buff)
{
int t;
int count = (int)(log(num)/log(16));
buff[count+1]=0;
for(;count >=0;--count)
{
t = num % 16;
num /= 16;
*(buff+count) = *(Hex+t);
}
}
int main()
{
char buf[BUFF_SIZE];
int a=0x06FE1234;
Covert2HexStr(a,BUFF_SIZE, buf);
printf("%s\n",buf);
}
/**
输出:6FE1234
**/
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询