How to convert an ASCII character into a hex value in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

int main() {
    char asciiChar = 'A'; 
    
    std::stringstream ss;
    ss << std::hex << static_cast<int>(asciiChar);
    std::string hexValue = ss.str();

    std::cout << "The hexadecimal value of '" << asciiChar << "' is: 0x" << hexValue << "\n";
}



/*
run:

The hexadecimal value of 'A' is: 0x41

*/

 



answered Dec 1, 2024 by avibootz

Related questions

2 answers 105 views
1 answer 132 views
1 answer 119 views
1 answer 136 views
1 answer 129 views
2 answers 146 views
...