Home > 2005-11 / 実装技術 > This Entry [com : 0][Tb : 0]
template <int Bit> struct bit;
template <> struct bit<0>
{ static const int value = 0; };
template <> struct bit<1>
{ static const int value = 1; };
template <unsigned long N>
struct binary
{
static const unsigned long value
= bit<N & 7>::value | (binary<N >> 3>::value << 1);
};
template <>
struct binary<0>
{ static const unsigned long value = 0; };
#define B(x) (binary<0##x>::value)
int x = B(0101); /* 0x05 */
http://cppemb.blog17.fc2.com/tb.php/42-ae047cc9
Comment