# you are given a base b and the description of a number m represented in that base as 5192131

You are given a base B, and the description of a number m represented in that base as “m=(X.Y)B” where X is the integer part of m and Y is the fractional part of m. Both parts are provided as arrays of numbers base B, so X[] is an array of size X.length and Y[] an array of size Y.length. Each X[i],Y[i] is a number among {0,1,…,B-1}.

The input is (B,X[],Y[]),R where R is the base in which number m=(X.Y)B is to be represented. In base R, m will be represented in the format m=(U.VW)R where U is the integer part of m and VW is the fractional part of m. The W part is used to represent the fractional part as an infinitely repeating pattern following a fixed non-repeating pattern V. We restrict the bases B and R to be 2 ≤ B,R ≤ 60. Note that the length of W is at most Blength(Y).

For example, in bases B=10 and R=2, the number 5/2 = (2.5)10 would be represented by (10.1)2 because (101/10)2 yields the pattern “10.1” when literally dividing (101)2 by (10)2. In the proposed format we obtain (10.1)2=(U.VW)2 where U=(10)2 V=(1)2 W=(0)2 since indeed (10.1)2 is the same as (10.10)2. The number 1/5 = (0.2)10 would be represented by (0.0011)2 because (1/101)2 yields the infinite pattern 0.0011001100110011… In the proposed format we obtain (0.0011)2=(U.VW)2 where U=(0)2 V=()2 W=(0011)2. The answer in base R is not unique since many representations are possible for the same number. For instance, all of the following are equivalent (0.5)10 = (0.49)10 (0.1)2 = (0.01)2 (0.0011)2 = (0.00110)2 = (0.001100)2 = (0.0011001)2 = …

The output is going to be of the format U[],V[],W[]. Any valid representation of the input number will be accepted. To simplify the input/output I have defined Java objects Number that contains a Base and three arrays U[],V[],W[]. Your method should be called “public Number convert(Number A, short Base)”. Please see the tester code I made available on the course web page and next page.

here is the tester code:

package conv;

public class tester {

public static void main(String[] args) {

class Number{

//=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

// your method for converting belongs here…

//=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

public Number convert(Number A, short Base) {

Number B=new Number();

B.Base=Base; B.Int=A.NonRep; B.NonRep=A.Int; B.Rep=A.NonRep;

// my code above is just to make sure it compiles and runs return B;

} //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

public void printShortArray(short[] S) {

for (int i = S.length-1; i>=0; i–) {

System.out.print(S[i]); } }

public void printNumber(Number N) {

System.out.print(“(“);

N.printShortArray(N.Int);

System.out.print(“.”);

N.printShortArray(N.NonRep);

System.out.print(“{“);

N.printShortArray(N.Rep);

System.out.print(“})_”);

System.out.println(N.Base); }

short Base; short[] Int,NonRep,Rep; };

Number N1=new Number() ; N1.Base=10; N1.Int=new short; N1.NonRep=new short; N1.Int=1; N1.Int=9; N1.NonRep=2; N1.NonRep=4; N1.NonRep=7; N1.Rep=new short; N1.printNumber(N1); Number N2=new Number() ; short R=2; N2=N1.convert(N1,R); N2.printNumber(N2); } }