c 十进制转换成十六进制
//输入一个整数,转化成十六进制N,nL nH 分别为无符号型双字节整数 N 的低位和高位字节
#include<stdio.h>
int main()
{
int a, b, i;
char s[10];
char arr[10];
scanf("%d",&a);
if(a == 0)
{
printf("error input\n");
return 0;
}
i = 0;
while(a > 0)
{
b = a%16;
if(b < 16)
s[i] = b;
i++;
a = a / 16;
}
printf("i = %d\n",i);
if(i==4)
{
arr[8] |= s[3]<<4;
arr[8] |= s[2];
arr[9] |= s[1]<<4;
arr[9] |= s[0];
}else if(i==3){
arr[8] |= s[2];
arr[9] |= s[1]<<4;
arr[9] |= s[0];
}else if(i==2){
arr[8] = 0;
arr[9] |= s[1]<<4;
arr[9] |= s[0];
}else{
arr[8] = 0;
arr[9] = s[0];
}
for(i--; i >= 0; i--)
{
printf("%d\n", s[i]);
}
printf("arr[8] = %x \n",arr[8]);
printf("**********\n");
printf("arr[9] = %x \n",arr[9]);
return 0;
}