爲什麼我們使用+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/ –