100. Convert Hexadecimal String to Integer Without strtol or sscanf functions

In embedded systems, you often receive hex strings from serial terminals or config files, like "1A3F", and need to convert them into integers — without using strtol(), sscanf(), or other library functions.

Your task is to:

  • Read a hex string of up to 4 characters (e.g., "1A3F")
  • Convert it into a uint16_t integer
  • Handle both uppercase and lowercase (e.g., "af" = "AF" = 175)


Example-1

Input: 1A3F
Output: 6719


Example-2

Input: AF
Output: 175


Example-3

Input: 0000
Output: 0


Example-4

Input: ffff
Output: 65535


 

Loading...

Input

1A3F

Expected Output

6719