mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 14:43:10 -05:00
15 lines
270 B
C
15 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;
|
||
|
}
|