While there is no function for directly reading binary numbers, there are strtox functions (where x represents the data type) to convert a string containing a binary number (or the number of any other base) to a numeric value.
So, the solution is to read the number as a string first and then convert it.
Example:
char input[100]; char *endpointer; <read input using either C or C++ syntax> int n = (int) strtol(input, &endpointer, 2);
source share