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
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.