c++ - How to cast from hex to int and char? -
is there way convert/cast hex decimal , form hex char? example if have:
string hexfile = string(argv[1]); ifstream ifile; if(ifile) ifile.open(hexfile, ios::binary); int = ifile.get(); // getting hex form hexfile , want char c = ifile.get(); // convert decimal representation int , char
thank you.
std::string s="1f"; int x; std::stringstream ss; ss << std::hex << s; ss >> x; std::cout<<x<<std::endl; //this base 10 value std::cout<<static_cast<char> (x)<<std::endl; //this ascii equivalent
Comments
Post a Comment