//将一个任意输入的10进制数转化为16进制形式输出
#include<stdio.h>
#include<stdio.h>
#define MAXSIZE 11
void ten20x(unsigned int a,char *p)
{
int i;
int j = 2;
int sum = 0;
int count = 0;
unsigned int mask = 0x80000000;
*(p + 0) = '0';
*(p + 1) = 'X';
*(p + 10) = '\0';
while(count < 8)
{
for(i = 0; i < 4; i++)
{
if((a & mask) == mask)
{
sum = sum * 2 + 1;
}
else
{
sum = sum * 2 + 0;
}
a = a << 1;
}
if(sum < 10)
{
*(p + j) = sum + '0';
j++;
}
else
{
*(p + j) = sum - 10 + 'a';
j++;
}
sum = 0;
count++;
}
}
}
int main()
{
unsigned int ver = 0;
char sixtn[MAXSIZE];
printf("please input a num \n");
scanf("%d",&ver);
ten20x(ver,sixtn);
printf("%d 的16进制为 %s\n",ver,sixtn);
return 0;
}