i want to show my string( message) in hexadecimal display( shows like hex editor) with c++ or visual c++
How to turn string to hex in c++?
This is a C++ program that performs the asked conversion by using the "%02X" print format specifier for each character of the string
#include "string.h"
void main(int argc)
{
char *mystring="Hello World";
for(int i=0;i%26lt;strlen(mystring);i++)
printf("%02X ",mystring[i]);
}
Reply:If I remember correctly, you have to take the string into chars. Then each char into acsii, then to byte. Then do the math to make the byte into hex. You need an array and one function passing in what type you want, in your case hex.(8)
A=65=01000001=41 hex.
0100 0001
4 1
The binary is separated in 4 bits then added. I think you have to use shift bits to count them
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment