开发者

CRC32 (Cyclic Redundancy Checksum) to string

If I have CRC32 (Cyclic Redundancy Checksum), th开发者_如何学Goen how can I get string from it?


The question is ambiguous.

If you mean "how can I convert the CRC32 integer to a string?", that is fairly easy. You can use a std::ostringstream or the sprintf() or itoa() functions.

If, as I suspect, you mean "I have a CRC32 generated from a string and I want to get back to the original string", then the answer is "it is impossible". CRC is a one-way transformation and there is no way to go backwards.


If you want to get the crc32_value as an hexadecimal string:

char crc32_string[64];
sprintf(crc32_string, "%8X", crc32_value);

You were not clear enough what format, what kind of string you want. Look at MSDN to find out which sprintf works for you. There are plenty of them with a more secure parameter checking.


The C++ way to convert an hexadecimal number to a string is the following :

std::stringstream s;
s << std::hex << crc32 /*the CRC32 number that you have computed somewhere*/;

std::string resultString = s.str();

Hope this answers your question. Otherwise precise what you expect !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜