Method Deck / other

Number base conversion

Converts a number represented in one base (2 to 36) to its representation in another base.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Positional notation: a number in base b is a sum of digit_i * b^i, where digits range from 0 to b-1 and digits above 9 are written as letters A (10) through Z (35).
  2. Parse value as an integer in from_base to get its numeric value.
  3. Re-express that numeric value in to_base, most significant digit first, using the same digit/letter convention.
  4. Digits/letters in the output are uppercase.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"value":"FF","from_base":16,"to_base":10}255
test vector: decimal to binary{"value":"255","from_base":10,"to_base":2}11111111

Published card