#include <stdio.h> #include <stdint.h> uint16_t binary_to_uint(const char *str) { uint16_t Number = 0; uint16_t len = 0; while( str[len] != '\0'){ len++; } int digit = 1; for(int i = len; i > 0; i--){ if(str[i - 1] == '1') { Number += digit; } digit *= 2; } return Number; } int main() { char bin[20]; scanf("%s", bin); printf("%u", binary_to_uint(bin)); return 0; }
Test Cases
Test Results
Input
1010
Expected Output
10