Leap, Difference of Squares, Grains, Collatz Conjecture, Queen Attack, Darts, Hamming, and Space Age completed yesterday. Binary and Linked List completed today.
22 lines
460 B
C
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;
|
|
}
|