Seth King wrote:
I am used to programming in embedded C and I want to input a binary number
into an int.
usually I would just use bin as a suffix or b as a prefix
int x = b001 or int x = 001110bin
There's no binary literal in C/C++. It's possible to implement it in C++
using template metaprogramming:
template<unsigned int N>
struct binary
{
enum { digit = N % 10 };
enum { value = digit + (binary<N / 10>::value * 2) };
};
template<>
struct binary<0>
{
enum { value = 0 };
};
int x = binary<001110>::value;
To convert a number to binary at runtime, just mask the upper bit and
shift left (multiply by 2) in a for loop.
Tom