Write a program that converts decimal numbers to hexadecimal, i.e., from base 10 to base 16.
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.
10
16
12648430
2989
a
10
c0ffee
bad
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
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/dec2hex