print the binary data
C++
template <typename T>
void printb(const T& t)
{
const size_t len = sizeof(T) * 8;
char s[len + 1];
typedef unsigned long long ull;
auto buff = const_cast<ull&>(reinterpret_cast<const ull&>(t));
s[len] = '\0';
for (size_t i = len - 1; i != (size_t)-1; --i)
{
s[i] = buff & 1 ? '1' : '0';
buff >>= 1;
}
cout << s;
}
网友评论