开发者

Character [hex] to integer

I tried using atoi function to do this, but it didn't work.

I want to convert a string that says "0x44" to an integer (as 0x44 or its decimal equivalent).

Does anyone know of an开发者_Go百科y functions that could do that?


Yes. Use strtol instead, and specify 0 as the base.


I think this is what you are looking for...

#include<stdio.h>
#include<stdlib.h>

void main() {
  char* hex = "0x44";
  int i;

  sscanf( hex, "%x", &i );
  printf("%d\n", i);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜