Converting a string with a hexadecimal representation of a number to an actual numeric value

前端 未结 6 934
渐次进展
渐次进展 2020-12-21 10:49

I have a string like this:

\"00c4\"

And I need to convert it to the numeric value that would be expressed by the literal:

0         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 11:01

    #include 
    
    int main()
    {
            const char *str = "0x00c4";
            int i = 0;
            sscanf(str, "%x", &i);
            printf("%d = 0x%x\n", i, i);
            return 0;
    }
    

提交回复
热议问题