为什么我们使用+55将十进制转换为十六进制数。在这段代码中,我们使用+48将整数转换为字符。当临时< 10。但是当temp> = 10时,我们使用+55。这是什么意思+55?将十进制转换为十六进制数
#include<stdio.h>
int main(){
long int decimalNumber,remainder,quotient;
int i=1,j,temp;
char hexadecimalNumber[100];
printf("Enter any decimal number: ");
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
temp = quotient % 16;
//To convert integer into character
if(temp < 10)
temp =temp + 48;
else
temp = temp + 55;
hexadecimalNumber[i++]= temp;
quotient = quotient/16;
}
printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%c",hexadecimalNumber[j]);
return 0;
}
http://www.asciitable.com/ –