public static Pair < BigInteger , Boolean > midpoint ( BigInteger left , BigInteger right , int sigbits ) { BigInteger midpoint ; boolean remainder ; if ( left . compareTo ( right ) < 0 ) { BigInteger sum = left . add ( right ) ; remainder = sum . testBit ( 0 ) ; midpoint = sum . shiftRight ( 1 ) ; } else { BigInteger max = TWO . pow ( sigbits ) ; // wrapping case BigInteger distance = max . add ( right ) . subtract ( left ) ; remainder = distance . testBit ( 0 ) ; midpoint = distance . shiftRight ( 1 ) . add ( left ) . mod ( max ) ; } return Pair . create ( midpoint , remainder ) ; }
Given two bit arrays represented as BigIntegers containing the given number of significant bits calculate a midpoint .