Convert a hexadecimal string into its decimal integer equivalent. The input contains digits 0 through 9 and letters A through F (case insensitive). Each position from left to right represents a power of 16, with the rightmost character being 16 to the power of 0. Return null for null input. Assume the input is always a valid hex string when non-null.
Examples:
Input: hex = 'FF'
Output: 255
Explanation: F times 16 plus F equals 15 times 16 plus 15
Input: hex = '1A'
Output: 26
Explanation: 1 times 16 plus 10 equals 26
Input: hex = '0'
Output: 0
Explanation: Single zero digit
Input: hex = 'abc'
Output: 2748
Explanation: Lowercase letters are valid; a times 256 plus b times 16 plus c
Input: hex = null
Output: null
Explanation: Null input returns null
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.