template<long int N
class binary
{
public:
enum {
bit = N % 10,
value = bit + (binary<N/10::value << 1)
};
};
class binary<0
{
public:
enum {
bit = 0,
value = 0
};
};
//
// Examples
//
#include <stdio.h
void main()
{
printf("9 = %i\n255 = %i\n37351 = %i\n16843009 = %li\n",
binary<1001::value, //this compiles to "push 9" for example
binary<11111111::value,
binary<11100111::value | binary<10010001::value << 8, //you can live with this
binary<1::value | binary<1::value<<8 |
binary<1::value<<16 | binary<1::value<<24 //kinda overkill, I know !
);
} |