将计算从int转换为Bigint Java代码

时间:2018-04-16 09:01:03

标签: java bigint

您好我试图将以下计算转换为与bigint一起使用。我已按照第二个代码段转换它,它运行时没有错误,但它没有返回相同的结果。我错误地改变了哪些想法?

while (exponent > 0)
    {
        int current_bit = exponent % 2;
        if (current_bit == 1)
          //  System.out.println("A" + result);
            result = (result * base) % modulus;
        //System.out.println("B" + result);
            exponent = exponent / 2;
        base = (base * base) % modulus;
       // System.out.println("C" + result);

    }
    return result;




    while (exponent.compareTo(BigInteger.valueOf(0)) == 1)
    {
        BigInteger current_bit = exponent.mod(BigInteger.valueOf(2));
       // System.out.println(exponent);
        if (current_bit == BigInteger.valueOf(1));
            //System.out.println("A" + result);
            result = (result.multiply(base)).remainder(modulus);
        //System.out.println("B" + result);
        exponent = exponent.divide(BigInteger.valueOf(2));
        base = (base.multiply(base)).remainder(modulus);
        //System.out.println("C" + result);
    }

    return result;

0 个答案:

没有答案