tags:

views:

75

answers:

2

Hi, i have a very long hex string in a byte array and I would like to format the output of that byte array such that it shows 0x??,0x??. The reason for this because I have a key that I am making and I don't want to type out a 512bit key like that. Any native code that could help me do that would be appreciated.

basically, i have a rsa key generated in hex and was hoping to use that as a static byte array. But, i dont want to type it all out {0x??, 0x??} etc

thanks in advance! you guys are the best!

+1  A: 

For each byte in the array: cout << "0x" << hex << unsigned(theByte) << ","; where theByte is the value (hopefully an unsigned char) that you want to print.

Mike DeSimone
A: 
cout.setf(ios::hex, ios::basefield);
cout << "0x" << val << endl;

or in printf format

printf("0x%x", val)
grokus