Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define PRINT_HEX(a) cout << hex << "Hex: 0x" << a << endl;
- using namespace std;
- void printCharStrAsBytes(char* str){
- while(*str){
- cout << hex << (int)(*str++) << " ";
- }
- cout << endl;
- }
- void printWCharStrAsBytes(wchar_t* str){
- while(*str){
- char* asChar = reinterpret_cast<char*>(str);
- for(size_t i = 0; i < sizeof(*str); i++){
- cout << hex << (int)asChar[i] << " ";
- }
- str++;
- }
- cout << endl;
- }
- template<class T>
- union Union{
- T val;
- char bytes[sizeof(T)];
- };
- template<class T>
- void printInHexWithOrder(T a){
- Union<T> u;
- u.val = a;
- for(size_t i = 0; i < sizeof(T); i++){
- cout << hex << (int)u.bytes[i] << " ";
- }
- cout << endl;
- }
- int main(){
- int num = 0x12345678;
- printInHexWithOrder(num);
- printCharStrAsBytes("asfsaf");
- cout << "WCHAR" << endl;
- printWCharStrAsBytes(L"Русская строка");
- cout << sizeof(wchar_t) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement