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