index | submit | rank | book

hex2dec – Hexadecimal to decimal

Write a program that converts hexadecimal numbers to decimal.

Input will consist of several lines each with an hexadecimal number h of up to 7 hexadecimal digits. The hexadecimal digits representing quantities from 0 to 15 are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. Letters are given in lowercase.

For each line of input, output should contain a line with the decimal representation of the corresponding input number.

Example Input

a
10
c0ffee
bad

Example Output

10
16
12648430
2989

Scoring

Hints

Remember the characters '0' through '9' are different than the numeric values 0 through 9. You can create a function which converts between both by using an if or case expression.

try first: bin2dec

try also: dec2hex

try next: base2base

index | submit | rank | book

Copyright © 2020-2021 Rudy Matela
All rights reserved