exercism/c/binary/binary.c

15 lines
270 B
C
Raw Normal View History

2024-08-14 17:30:14 -04:00
#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;
}