Write a program that converts between numerical bases between 2 and 36 digits.
Input will consist of several lines each with a number n, a source base s and a destination base d where 0 ≤ n < 1 000 000 000 and 2 ≤ s, d ≤ 36.
The number n is given in base s.
For each line of input, output should contain a line with the representation of number n in base d.
In this exercise, digits valued from 0 to 35 are represented first by regular digits then by the English alphabet: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, …, x, y, z. In other words, the letters a through z are valued 10 through 35.
360 10 12
1010 2 8
ff00ff 16 2
260
12
111111110000000011111111
Remember the characters '0'
and '1'
are different
than the numeric values 0
and 1
.
You can create a function which converts between both
by using an if
or case
expression.
try first: bin2dec dec2bin hex2dec dec2hex
try next: bool-not
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/base2base