#include <stdio.h> #include <stdint.h> uint16_t hex_to_uint(const char *str) { // Your logic here uint16_t res = 0; uint8_t value; for (uint8_t i = 0; str[i] != '\0'; i++) { if (str[i] >= '0' && str[i] <= '9') { value = str[i] - '0'; }else if (str[i] >= 'A' && str[i] <= 'Z') { value = 10 + (str[i] - 'A'); }else if (str[i] >= 'a' && str[i] <= 'z') { value = 10 + (str[i] - 'a'); }else{ value = 0; } res = (res << 4) + value; } return res; } int main() { char hex[10]; scanf("%s", hex); printf("%u", hex_to_uint(hex)); return 0; }
Test Cases
Test Results
Input
1A3F
Expected Output
6719