avatar Bite 299. Base converter

For this challenge, you are going to have write a function to convert a base 10 integer into any base, as long as that base is no lower than 2 and no larger than 36.

Here’s a nice explanation of how it’s traditionally done: Base Conversion Method.

For example:

- 126 converted to base 2 is 1111110

- 126 converted to base 4 is 1332

- 126 converted to base 8 is 176

- 126 converted to base 16 is 7E

If the base is out of that range, the function should raise a ValueError.

The returned value should be a string. That’s it, happy coding!

 

Login and get coding
go back Intermediate level
Bitecoin 3X

60 out of 63 users completed this Bite.
Will you be the 61st person to crack this Bite?
Resolution time: ~41 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 2.33 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help