exercism/c/binary/binary.c
2024-08-14 17:30:14 -04:00

14 lines
270 B
C

#include "binary.h"
#include <stdio.h>
int convert(const char *input) {
int res = 0;
for (size_t i = 0; input[i]; ++i) {
if (input[i] != '0' && input[i] != '1') {
res = INVALID;
break;
}
res = res * 2 + (input[i] - '0');
}
return res;
}