Advertisement
mgostih

String to Hex

Apr 4th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iomanip>
  4. using namespace std;
  5. char * HexConvert(char* message,int lenght){
  6.     ostringstream str;
  7.     for (int i = 0; i < (lenght-1); i++){
  8.         str << hex << setw(2) << setfill('0') << (int)((unsigned char)message[i]);
  9.     }
  10.     str << '\x00';
  11.     auto ret = new char [(lenght * 2)+1];
  12.     strncpy_s(ret,(lenght*2)+1, (char*)str.str().c_str(), (lenght * 2) + 1);
  13.     return ret;
  14. }
  15. int _tmain(int argc, _TCHAR* argv[])
  16. {
  17.     cout << HexConvert("\xff\x00", 3)<<endl;
  18.     system("PAUSE>NUL");
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement