How do I print bytes as hexadecimal?
问题 I know in C# you can use String.Format method. But how do you do this in C++? Is there a function that allows me to convert a byte to a Hex?? Just need to convert a 8 byte long data to Hex, how do I do that? 回答1: Well you can convert one byte (unsigned char) at a time into a array like so char buffer [17]; buffer[16] = 0; for(j = 0; j < 8; j++) sprintf(&buffer[2*j], "%02X", data[j]); 回答2: If you want to use C++ streams rather than C functions, you can do the following: int ar[] = { 20, 30, 40