Convert binary format string to int, in C

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 🙂

Leave a Comment