The assignment is to simulate the BigInteger class in Java using an array that represents the integer.
For example the array [5,4,3,2,1] would be equal to 12345, where the 0 element is the 5.
We have to do methods for addition, subtraction, multiplication, and division. I have already done add, subtract, and multiply, but now I'm stuck on division. I can't come up with a way to do this. I don't see long division working because I'd have to take the numbers out of the array and make it a real integer, but that won't work because the array can be quite large. I don't want to repeatedly subtract the divisor, although I might do it if I can't come up with another solution.
I'm trying to figure something out where each element is considered a power of 10. Such as 123 = 1x^2 + 2x + 3, where x = 10, but I still can't figure anything out. Synthetic division won't work since the divisor isn't always a monomial. Anyone know of an algorithm that can do this? Can be in any language besides Java, I just need an algorithm.
Big Thanks,
Thien
For example the array [5,4,3,2,1] would be equal to 12345, where the 0 element is the 5.
We have to do methods for addition, subtraction, multiplication, and division. I have already done add, subtract, and multiply, but now I'm stuck on division. I can't come up with a way to do this. I don't see long division working because I'd have to take the numbers out of the array and make it a real integer, but that won't work because the array can be quite large. I don't want to repeatedly subtract the divisor, although I might do it if I can't come up with another solution.
I'm trying to figure something out where each element is considered a power of 10. Such as 123 = 1x^2 + 2x + 3, where x = 10, but I still can't figure anything out. Synthetic division won't work since the divisor isn't always a monomial. Anyone know of an algorithm that can do this? Can be in any language besides Java, I just need an algorithm.
Big Thanks,
Thien
Comment