# Thread: decimal to hexadecimal

1. ## decimal to hexadecimal

I already understand how to convert it into it's numerical value, but i dont understand how to display the result into it's alphabetical value.
like the hexadecimal value of 26 = 1A.
i'm stuck at displaying the value as 26 = 110.

this is how i do so far :

can someone please point out my mistake ?

Code:
```#include <stdio.h>

int main ()
{

int ask = 26;
int a;
int b[9];
int c = 0;

while ( ask > 0 ) {

a = ask % 16;
if ( a == 10 ) {

b[c] = 'A';
}

if ( a == 11 ) {

b[c] = 'B';
}

if ( a == 12 ) {

b[c] = 'C';
}

if ( a == 13 ) {

b[c] ='D';
}

if ( a == 14 ) {

b[c] = 'E';
}

if ( a == 15 ) {

b[c] = 'F';
}
else {

b[c] = a;
}

c++;
ask = ask / 16;

}

while ( c ){

printf ("%d", b[--c]);

}
getchar ();
return 0;
}```

2. All your good work gets undone by the last else -- that else is only on the if a==15; if you've already set b[c] to 'A', well, too bad.

3. i try to replace that last else with

Code:
```if ( a < 10 ) {

b[c] = a;
}```
the result was still wrong. it end up displaying 165. any other suggestion ?

4. Originally Posted by prominababy
i try to replace that last else with

Code:
```if ( a < 10 ) {

b[c] = a;
}```
the result was still wrong. it end up displaying 165. any other suggestion ?
Well, that's what you wanted, wasn't it? 'A' is 65, after all.[0] If you want letters, why would you be printing ints with &#37;d?

[0]Obviously only on ASCII machines, but that's apparently what we're on.

Popular pages Recent additions