Is there a way for the user to input a binary number in C or C++?
If we write something like
int a = 0b1010;
std::cout << a << std::endl
While there is no function to read binary numbers directly, there are functions, strtox
(where x represents the data type) to convert a string containing a binary number (or a number of any other base) to a numeric value.
So the solution is to first read the number as a string and then convert it.
Example:
char input[100];
char *endpointer;
int n = (int) strtol(input, &endpointer, 2);