# string to actual hex value conversion

This is a discussion on string to actual hex value conversion within the C Programming forums, part of the General Programming Boards category; I'm pretty new to programming c and trying to get from ascii 0x39, 0x39 (99) to the actual hex value ...

1. ## string to actual hex value conversion

I'm pretty new to programming c and trying to get from ascii 0x39, 0x39 (99) to the actual hex value 0x63. I've searched many fora but couldn't find a good solution yet. For as far as I know there is no standard function to do this? I can get it to the string 0x36, 0x33 or to an integer, but the actual value 0x63 I don't know how to get. Hope you guys can point me in the right direction

I have been trying this:
Code:
```ascii f[2] = {0x39,0x39}; //0x39 , 0x39 , 0x39 , 0x39 , 0x2D , 0x31 , 0x32 , 0x2D , 0x33 , 0x31
char y[2];
int o;

int hj = atoi(&f[0]);
int jj = atoi(&f[1]);

o=jj+10*hj;

sprintf(y,"%x", o);```
I guess I should write a conversion function, but I don't know yet where to start..

2. You probably want to use sscanf to convert your hex string into a numerical value. Once a number you can then print it out in decimal/hex/oct with a printf call.

3. I have a string with numbers which I have to convert to the hex value because the other side expects this value.
I got this which works now does this seem a good solution?

Code:
```ascii f[2] = {0x39,0x39};
char gh[1];
int hj = atoi(&f[0]);

for(i = 0; i < 100; i++){
if(hj==i){
gh[0] = (char)i;
break;
}
}```

4. The whole for loop was not necessary off course I was just looking for the (char)hj; which I didn't knew before

5. I don't think you're understanding what you have to do. Try printf("%x", atoi(f)) and see how close that gets to what you're hoping to see. If it's different, explain what you hoped the answer would come out as.

6. yes this is somewhat embarrassing it is what I meant, I am developing an open AT application and it was not the standard library so I had to add the right library. Thanks!