I am trying to write a basic calculator. One of the things I want my calculator to have is a base arithmetic converter that gives an output when you input a base 10 integer.
I tried to write code for it on my own and it took nearly 3 hours just to figure out how to convert a number to a given base and it works good enough so far but I have one problem - when I try to convert an integer to base 2 (binary) my calculator does not work for numbers bigger than 1025.
I thought the problem was because there is a max value an integer can hold or something so I tried "BigInteger" but since it does not support remainder "%" operation I could not make it work.
else if(c.equals("Base")) {
g = 0;
l = 0;
System.out.println("Enter the number (Integer) you want to convert");
f = scan.nextInt();
System.out.println("Enter the arithmetic base you want for your new number");
m = scan.nextInt();
for (;f>=1;) {
h=f%m;
f=f/m;
k = (int)Math.pow(10,g);
g++;
l =l + (h*k);
}
System.out.println(l);
}
Sorry if the code is really bad and there are more efficent ways, i just wanted it to be mine instead of looking it up.
intvariable, since that limits you to 10 digits. You can use a String instead.ltoString, and you can eliminatekandg.