how do I print an unsigned char as hex in c++ using ostream?
Use: cout << “a is ” << hex << (int) a <<“; b is ” << hex << (int) b << endl; And if you want padding with leading zeros then: #include <iomanip> … cout << “a is ” << setw(2) << setfill(‘0’) << hex << (int) a ; As we are using C-style casts, … Read more