fork(1) download
  1. #include <string>
  2. #include <sstream>
  3. #include <iomanip>
  4. #include <iostream>
  5.  
  6. void create_hex_str(uint8_t *data, int len, std::string &tgt)
  7. {
  8. std::stringstream ss;
  9. ss << std::hex << std::setfill('0');
  10. ss << "\n";
  11. for (int i=0; i<len; i++)
  12. {
  13. ss << std::setw(2) << static_cast<unsigned>(data[i]) << " ";
  14. }
  15. tgt = ss.str();
  16. }
  17.  
  18. int main()
  19. {
  20. /* char buf[] = {
  21.   0x2,
  22.   0x0,
  23.   0x3,
  24.   0x3,
  25.   0x0,
  26.   0x0,
  27.   0x6,
  28.   0x4,
  29.   0x0,
  30.   0x2,
  31.   0x0,
  32.   0x0
  33.   }; */
  34.  
  35. char *buf = new char[12];
  36. buf[0] = 0x2;
  37. buf[1] = 0x0;
  38. buf[2] = 0x3;
  39. buf[3] = 0x3;
  40. buf[4] = 0x0;
  41. buf[5] = 0x0;
  42. buf[6] = 0x6;
  43. buf[7] = 0x4;
  44. buf[8] = 0x0;
  45. buf[9] = 0x2;
  46. buf[10] =0x0;
  47. buf[11] =0x0;
  48.  
  49. std::string hex_string;
  50. create_hex_str((uint8_t*)buf, 12, hex_string);
  51. std::cout << hex_string;
  52. }
  53.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
02 00 03 03 00 00 06 04 00 02 00 00