Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

2 Answers
Anvi Jain

Here we will see how to hide some string into some binary code (Here binary code is represented in hexadecimal number).

The approach is very simple. We can use the string stream to convert decimal number to hexadecimal numbers. Now from the string, we will read each character, and take its ASCII value, these ASCII values are converted into hexadecimal values. Then we can print them one by one.

Example

#include<iostream>
#include<sstream>
using namespace std;
string dec_to_hex(int decimal){ //function is used to convert decimal to hex
   stringstream my_ss;
   my_ss << hex << decimal;
   return my_ss.str();
}
main(){
   string my_string = "This is a sample text";
   for(int i = 0; i<my_string.length(); i++){
      cout << dec_to_hex(my_string.at(i)) << " ";
   }
}

Output

54 68 69 73 20 69 73 20 61 20 73 61 6d 70 6c 65 20 74 65 78 74

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.