index | submit | rank | book

dec2hex – Decimal do hexadecimal

Write a program that converts decimal numbers to hexadecimal, i.e., from base 10 to base 16.

Decimal do hexadecimal

Input will consist of several lines each with a decimal number d of up to 9 decimal digits.

For each line of input, output should contain a line with the hexadecimal representation of the corresponding input number. The hexadecimal digits representing quantities from 0 to 15 should be: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. Letters should be given in lowercase.

Example Input

10
16
12648430
2989

Example Output

a
10
c0ffee
bad

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: dec2bin

try also: hex2dec

try next: base2base

index | submit | rank | book

Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/dec2hex