# Sub Algorithms Base Values

**This content was STOLEN from BrainMass.com - View the original, and get the solution, here!**

? Write a sub-algorithm (subroutine) that given a number N in base 10 and a base value Base between 2 and 10 (inclusive), returns the representation of the decimal value N in the desired Base. For example, given N = 25, and Base = 2, it should return 11001.

Algorithm: Base_10_to_Any_Base

1.0 Given:

1.1 an integer N, a decimal value

1.2 an integer Base, a base between 2 and 10

2.0 Declare variable Result

...

? Write a sub-algorithm (subroutine) that given a string Number representing a number in some base and a base value Base between 2 and 10 (inclusive), returns the representation of Number as a decimal value. For example, given Number = 11001, and Base = 2, it should return 25.

Algorithm: Any_Base_to_Base_10

1.0 Given:

1.1 a string Number, a string of digits,

1.2 an integer Base, a base between 2 and 10

2.0 Declare variable Result

...

? Write an algorithm, that uses the above two sub-algorithms, given a number in some base from and a different base named to, converts the number from the original base to the desired base.

Algorithm: Any_Base_to_Any_Base

1.0 Given:

1.1 a string Number, a string of digits,

1.2 an integer From, a base between 2 and 10

1.2 an integer To, a base between 2 and 10

2.0 Declare variable Result

...

#### Solution Preview

1. Algorithm: Base_10_to_Any_Base

String Base_10_to_Any_Base(int N, int Base)

BEGIN

1. Define a string str = ""

2. While (N>0) Then

2.1. str = str + (N%Base)

2.2 N = N/Base

End ...

#### Solution Summary

Sub algorithm base values are examined. The expert declares the results.