exercism-c/binary/binary.c
Blizzard Finnegan b92478b09c
Init commit
Leap, Difference of Squares, Grains, Collatz Conjecture, Queen Attack,
Darts, Hamming, and Space Age completed yesterday.

Binary and Linked List completed today.
2025-01-11 18:45:47 -05:00

22 lines
460 B
C

#include "binary.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
int convert(const char *input){
size_t index;
int return_val = 0;
size_t length = strlen(input);
for(index = 0; index < length; ++index){
char get_char = input[index];
if(get_char != '0' && get_char != '1'){
return INVALID;
} else {
return_val += (pow(2,length-(index+1))) * (get_char - '0');
}
}
return return_val;
}