how to convert hex to int
-
Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.
-
Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.
Have you considered
strtol()
?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Have you considered
strtol()
?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
thanks a lot david, you solved the problem.
-
Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.
strtol
[^] function, called withbase=16
, does the magic, for instance:char * szHex = "0F";
char * szStop;
int i;
i = strtol(szHex, &szStop, 16);
printf("%s hex = %d dec\n", szHex, i);Please note the output of the program:
0F hex = 15 dec
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
strtol
[^] function, called withbase=16
, does the magic, for instance:char * szHex = "0F";
char * szStop;
int i;
i = strtol(szHex, &szStop, 16);
printf("%s hex = %d dec\n", szHex, i);Please note the output of the program:
0F hex = 15 dec
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]thanks alot pallini!