C++ binary constant/literal
问题 I'm using a well known template to allow binary constants template< unsigned long long N > struct binary { enum { value = (N % 10) + 2 * binary< N / 10 > :: value } ; }; template<> struct binary< 0 > { enum { value = 0 } ; }; So you can do something like binary<101011011>::value. Unfortunately this has a limit of 20 digits for a unsigned long long. Does anyone have a better solution? 回答1: Does this work if you have a leading zero on your binary value? A leading zero makes the constant octal