index | submit | rank | book

base2base – Converting between bases

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.

360 represented in different numeric bases

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.

Example input

360 10 12
1010 2 8
ff00ff 16 2

Example output

260
12
111111110000000011111111

Scoring

Hints

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

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved