121. Data Conversion and Encoding-i

Question.2

A developer parses a hex string from UART input:

uint16_t hex_to_int(const char *s) {
   uint16_t val = 0;
   while (*s) {
       char c = *s;
       int digit = (c >= 'A') ? (c - 'A' + 10) : (c - '0');
       val = (val << 4) | digit;
       s++;
   }
   return val;
}

What happens when the input is "af" (lowercase)?

Need Help? Refer to the Quick Guide below

Select Answer