how do I convert a byte buffer to a string?

Started by
3 comments, last by Fruny 17 years, 11 months ago
is there a function I can use to do this or do I have to write my own? I'm trying to use convert the number generated by CrypGenRandom() to a string. Let me know id I'm doing the CrypGenRandom() part right... BYTE MyBuff[16]; CryptGenRandom(hCryptProv,16,MyBuff); here's the prototype for the function: BOOL WINAPI CryptGenRandom( HCRYPTPROV hProv, DWORD dwLen, BYTE* pbBuffer );
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Advertisement
Do you want the string to be the decimal representation of the binary number in the buffer, or to be the ascii interpretation of the data in the buffer?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
ascii
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
What base do you want the number in? If you want base 2, 8, or 16 it's easy. If you want a 16-byte base 10 integer as a string... which is what I'm betting that you are looking for you have two choices:

1) download a bignum library (GNU gmp, OpenSSL, etc.)

or

2) write your own, which can be a neat exercise.
Quote:Original post by etsuja
ascii


std::string foo(MyBuff, MyBuff+16); will do it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement