Hexadecimal to Decimal Conversion - aloalgo

Hexadecimal to Decimal Conversion

Easy

Write a function that converts a given hexadecimal string to its decimal (base-10) integer equivalent. The input hexadecimal string can contain digits '0'-'9' and letters 'A'-'F' (case-insensitive). The function should return the decimal representation of the hexadecimal string.

Hexadecimal (base 16) numbers use sixteen distinct symbols: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'. Each position in a hexadecimal number represents a power of 16. For example, the hexadecimal number "1A" is equivalent to (1 * 16^1) + (10 * 16^0) in decimal, which is 16 + 10 = 26.

Example 1

Input
"1A"
Output
26
Explanation:

The hexadecimal '1A' is (1 * 16^1) + (10 * 16^0) = 16 + 10 = 26 in decimal.

Example 2

Input
"FF"
Output
255
Explanation:

The hexadecimal 'FF' is (15 * 16^1) + (15 * 16^0) = 240 + 15 = 255 in decimal.

Example 3

Input
"100"
Output
256
Explanation:

The hexadecimal '100' is (1 * 16^2) + (0 * 16^1) + (0 * 16^0) = 256 + 0 + 0 = 256 in decimal.

Loading...
Input
"1A"
Output
26

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!