// Ivan Novick // January 31, 2008 #include // This union allows us to access a long as if it was char array union BYTES { long number; char buf[]; }; int main(int argc, char** argv) { BYTES b; // this is the integer which represents "HI!" when access as a char array b.number = 2181448; // print out all the ascii codes of the string for (int i=0; i < sizeof(long); ++i) { std::cout << std::hex << (int)b.buf[i] << std::endl; } // print out the data as a string // "HI!" std::cout << b.buf << std::endl; return 0; }