Converting string of 1s and 0s into binary value

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char * ptr;
    long parsed = strtol("11110111", & ptr, 2);
    printf("%lX\n", parsed);
    return EXIT_SUCCESS;
}

For larger numbers, there as a long long version, strtoll.

Leave a Comment