Project 97: Decimal to Base K

Difficulty Level: High

Converting Decimal Numbers to Other Bases

Example 1: Convert 47 base 10 to base 3.

1*3^3 + 2*3^2 + 0*3^1 + 2*3^0, so 47 base 10 is equivalent to 1202 base 3.

Example 2: Convert 100 base 10 to base 7.

2*7^2 + 0*7^1 + 2*7^0, so 100 base 10 is equivalent to 202 base 7.

Project 97: Variables 'decimal' and 'base' have been initialized.  

decimal is the base 10 number (47 for example 1)

base is the base to convert to (3 for example 1)

Task: Appropriately initialize the variable 'digits' that represents the number equivalent to decimal in the given base.

Example: if decimal = 100 and base = 7, then digits should be [2, 0, 2] (Explained in example 2).

Note: You can assume that 'digits' has been initialized as empty array (JavaScript) or an empty ArrayList (Java).

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0