【发布时间】:2021-08-04 20:41:12
【问题描述】:
编辑:看起来我犯了一个愚蠢的错误:)
有人知道为什么下面的代码会产生 2 个不同的十六进制字符串吗?
开头似乎有一个额外的字节。 boost的十六进制和非十六进制不能很好地协同工作还是我错过了什么?欢迎使用 C++17 更好的替代品!
std::string hex(const std::vector<uint8_t>& v)
{
std::string to;
boost::algorithm::hex(v.begin(), v.end(), std::back_inserter(to));
return to;
}
std::vector<uint8_t> unhex(const std::string& hex)
{
std::vector<uint8_t> bytes = {0};
boost::algorithm::unhex(hex, std::back_inserter(bytes));
return bytes;
}
int main()
{
string payload = "01630B917123862732F0000002EF18";
cout << payload << endl;
cout << hex(unhex(payload)) << endl;
}
输出:
01630B917123862732F0000002EF18
0001630B917123862732F0000002EF18
【问题讨论】: