Hi everyone,
I am working on a little function that calculates a decimal value of
a hexadecimal input, when I run the program it gives me negative
numbers and I cann't figure out why it doing so:
can anyone have look at my code and have look what I am getting wrong ?
here is the code with test main:
Thanks in advanceCode:code void main(void) { int X; int Y; printf("enter a hex value : "); scanf("%x", & Y); X = Convert( Y); printf(" corresponding decimal value is %d\n", X); } int Convert(char val ) { if ((val >= 0 ) && (val <= 9)) { val = (int)val - 0; return val ; } else if(val=='A'||val=='B'|| val=='C'||val=='D'||val=='E'||val=='F' ) { val = (int)val - (int)('A') + 10; return val; } }



LinkBack URL
About LinkBacks


