how to convert string to hexadecimal?

后端 未结 3 1457
难免孤独
难免孤独 2020-12-06 14:55

I have a string 0xFF, is there any function like atoi which reads that string and save in a uint32_t format?

3条回答
  •  醉话见心
    2020-12-06 15:39

    const char *str = "0xFF";
    uint32_t value;
    if (1 == sscanf(str, "0x%"SCNx32, &value)) {
        // value now contains the value in the string--decimal 255, in this case.
    }
    

提交回复
热议问题