为什么我们使用+ 55将十进制转换为十六进制数.在这段代码中,我们使用+48将整数转换为字符.当temp <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;
}
Run Code Online (Sandbox Code Playgroud) 我的代码有什么问题,任何人帮助我plz.这是一个十进制到二进制的转换.根据我的代码,输出将是2为10,3为11但它输出总是添加最后一个值,如3显示1110,添加以前的输出.我现在应该怎么做 ?帮我PLZ?
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
long int decimalNumber,quotient;
int binaryNumber[100],i=0,j;
printf("Enter any decimal number: ");
//scanf_s("%ld",&decimalNumber);
while(scanf_s("%ld",&decimalNumber)==1)
{
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf("Equivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j>= 0;j--)
printf("%d",binaryNumber[j]);
printf("\n");
printf("Enter any decimal number: ");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)