drahos
asked on
How to implement own biginteger class in java?
Hello experts,
Please help me to implement my own BigInteger class in java. I'm totally lost in this assignment.
I should hold the biginteger value in some array (array of bytes) in little endian, but i don't now how to do this.
If it's too difficult, implement/override the methods toString(), equals(Object obj), compareTo(BigInteger value) can be helpfull.
Thank for help
here is my demo:
Please help me to implement my own BigInteger class in java. I'm totally lost in this assignment.
I should hold the biginteger value in some array (array of bytes) in little endian, but i don't now how to do this.
If it's too difficult, implement/override the methods toString(), equals(Object obj), compareTo(BigInteger value) can be helpfull.
Thank for help
here is my demo:
public class BigInteger implements Comparable<Object> {
private boolean signum;
public BigInteger(){}
public BigInteger(long value){}
public BigInteger(BigInteger value){}
public BigInteger(String value){}
public String toString(){
}
public boolean equals(Object obj){
}
public int compareTo(BigInteger value) {
}
public int compareTo(Object o) {
}
public double doubleValue(){
}
public double floatValue(){
}
public double intValue(){
}
public double longValue(){
}
public int getMagnitudeLength(){
}
public BigInteger add(BigInteger value){
}
public BigInteger add(int value){
}
public static void main (String[] args){
BigInteger c1 = new BigInteger(1234);
System.out.println("c1 = " + c1);
BigInteger c2 = new BigInteger(c1);
System.out.println("c2 = " + c2);
BigInteger c3 = new BigInteger("-456");
System.out.println("c3 = " + c3);
System.out.println("c1 == c2: " + c1.equals(c2));
System.out.println("c1 == c3: " + c1.equals(c3));
System.out.println("c1 ? c3: " + c1.compareTo(c3));
c2 = c2.add(100).add(c1);
System.out.println("c2 = " + c2);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BigInteger classes are usually String-oriented. You might like to store each digit in ascii in the array beginning with the most significant digit
Help provided, which should be acknowledged
/** All integers are stored in 2's-complement form.
63: * If words == null, the ival is the value of this BigInteger.
64: * Otherwise, the first ival elements of words make the value
65: * of this BigInteger, stored in little-endian order, 2's-complement form. */