The strtol
function in the standard library takes a “base” parameter, which in this case would be 2.
int fromBinary(const char *s) {
return (int) strtol(s, NULL, 2);
}
(first C code I’ve written in about 8 years 🙂
More Related Contents:
- What is wrong in the following program? [closed]
- Value changing when I pass array into function
- Why is “while ( !feof (file) )” always wrong?
- Why should you use strncpy instead of strcpy?
- convert big endian to little endian in C [without using provided func] [closed]
- Undefined reference to sqrt (or other mathematical functions)
- How to simulate an EOF?
- How does C Handle Integer Literals with Leading Zeros, and What About atoi?
- parallel prefix (cumulative) sum with SSE
- Does C support overloading?
- listen() ignores the backlog argument?
- Store and work with Big numbers in C
- The spiral rule about declarations — when is it in error?
- Core dumped, but core file is not in the current directory?
- Converting an int into a 4 byte char array (C)
- In C, what is the correct syntax for declaring pointers?
- Time complexity of a recursive algorithm
- “UNDEFINED REFRENCE TO clrscr();” [duplicate]
- strtok segmentation fault
- scanf(“%c”) call seems to be skipped
- How can I return a character array from a function in C?
- How can I handle SIGCHLD?
- How to properly flush stdin in fgets loop
- .bss vs COMMON: what goes where?
- Segmentation fault in btree implementation
- What is the use of .exp and what is the difference between .lib and .dll?
- What are scanf(“%*s”) and scanf(“%*d”) format identifiers?
- Why do compilers insist on using a callee-saved register here?
- Is there a standard way to do an fopen with a Unicode string file path?
- ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] [duplicate]