【发布时间】:2011-06-09 00:20:23
【问题描述】:
我有一个表示 base64 值的字符串。我想将此字符串从 base64 转换为十六进制。我在 Ubuntu 10.10 上使用 C++ 工作。我有以下代码:
std::string ssir = "DNQwSinfOUSSWd+U04r23A==";
std::string dec=(base64_decode(ssir));
std::stringstream ss;
for (int i=0; i<dec.size(); ++i) {
if (i != 0) ss << ':';
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(dec[i]);//(int)(dec[i]);
}
std::string res;
res= ss.str();
cout<<"the ress is: "<<res<<std::endl;
结果是:
0c:ffffffd4:30:4a:29:ffffffdf:39:44:ffffff92:59:ffffffdf:ffffff94:ffffffd3:ffffff8a:ffffff6:ffffffdc
这是正确的,除了那些ffffffff。我能做些什么来解决这个问题?如果我想将我的十六进制结果写入std::vector<unsigned char> x,我该怎么办?
【问题讨论】:
-
请注意,您所说的“六进制结果”是一个字符串,因此将其存储在
std::string中会更有意义。 -
重复(同一用户,昨天):base 64 string to hexa string