Converting a hex string to a byte array

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

    i've modified TheoretiCAL's code

    uint8_t buf[32] = {};
    std::string hex = "0123";
    while (hex.length() % 2)
        hex = "0" + hex;
    std::stringstream stream;
    stream << std::hex << hex;
    
    for (size_t i= 0; i > buf[i];
    

提交回复
热议问题