Converting a hex string to a byte array

后端 未结 19 1940
时光取名叫无心
时光取名叫无心 2020-11-22 12:10

What is the best way to convert a variable length hex string e.g. \"01A1\" to a byte array containing that data.

i.e converting this:

st         


        
19条回答
  •  粉色の甜心
    2020-11-22 13:01

    If you can make your data to look like this e.g array of "0x01", "0xA1" Then you can iterate your array and use sscanf to create the array of values

    unsigned int result;
    sscanf(data, "%x", &result);         
    

提交回复
热议问题