프로그래밍/Java

BigInteger끼리 지수승 연산 함수

jonelove71 2011. 5. 6. 14:49
biginteger^biginteger

public static BigInteger pow(BigInteger base, BigInteger exponent)
 {   
  BigInteger result = BigInteger.ONE;  
  while (exponent.signum() > 0) {    
   if (exponent.testBit(0)) result = result.multiply(base);     
   base = base.multiply(base);    
   exponent = exponent.shiftRight(1);  
}   
  return result;
 }