[英]Convert Hexdump to string in c
Is there a way to convert a hexdump eg aec4d2f3c6a4e70ea6cea074f65812d2a34b180cc92b817edcd867167e7a91c5beb942f0 to a string in c so that every two hexadecimal digits make a char? 有没有一种方法可以将十六进制转储(例如aec4d2f3c6a4e70ea6cea074f65812d2a34b180cc92b817edcd867167e7a91c5beb942f0)转换为c中的字符串,以便每两个十六进制数字组成一个字符? If so, what?
如果是这样,该怎么办?
Reads from stdin and prints to stdout: 从stdin读取并打印到stdout:
int main()
{
int ch;
while(scanf("%2x", &ch) == 1)
putchar(ch);
}
I think you can modify it easily yourself for your specific source and destination requirements. 我认为您可以根据自己的特定源和目标要求轻松地对其进行修改。
One of the ways: 方式之一:
size_t unBytes = strHex.size() / 2;
std::string strResult(unBytes, 0);
for (size_t i = 0; i < unBytes; ++i)
{
std::istringstream in(strHex.substr(2*i, 2));
int byte = 0;
in >> std::hex >> byte;
strResult[i] = byte;
}
Use scanf with %hhx
repeatedly. 重复将scanf与
%hhx
一起使用。 See man scanf
. 见
man scanf
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.