C++ (Qt)template <class T>void PrintBin( const T & src ){ char dstBuf[65]; char * buf = dstBuf + sizeof(dstBuf); *(--buf) = 0; size_t num = sizeof(T); long long val; switch (num) { case 1: case 2: val = src; break; case 4: val = *(int *) &src; break; case 8: val = *(long long *) &src; break; default: assert(0); // invalid T } for (size_t i = 0; i < num * 8; ++i) { *(--buf) = (val & 1LL) ? '1' : '0'; val >>= 1; } printf("binary: %s\n", buf);}