Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created December 23, 2012 17:05
Show Gist options
  • Save ElemarJR/4364455 to your computer and use it in GitHub Desktop.
Save ElemarJR/4364455 to your computer and use it in GitHub Desktop.
#include <iostream>
template <unsigned long N>
struct binary {
static unsigned const value =
binary<N/10>::value * 2
+ N % 10;
};
template <>
struct binary<0> {
static unsigned const value = 0;
};
int main()
{
unsigned const two = binary<10>::value;
unsigned const five = binary<101>::value;
std::cout
<< two << std::endl
<< five << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment