Converting a hex string to a byte array

后端 未结 19 2132
时光取名叫无心
时光取名叫无心 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:06

    You can use boost:

    #include 
    
    char bytes[60] = {0}; 
    std::string hash = boost::algorithm::unhex(std::string("313233343536373839")); 
    std::copy(hash.begin(), hash.end(), bytes);
    

提交回复
热议问题