/** * Calculate bitlength of contents of the first len elements an int array, * assuming there are no leading zero ints. */ private static int bitLength(int[] val, int len) { if (len == 0) return 0; return ((len - 1) << 5) + bitLengthForInt(val[0]); }
/** * Calculate bitlength of contents of the first len elements an int array, * assuming there are no leading zero ints. */ private static int bitLength(int[] val, int len) { if (len == 0) return 0; return ((len - 1) << 5) + bitLengthForInt(val[0]); }
/** * Returns the mag array as an array of bytes. */ private byte[] magSerializedForm() { int len = mag.length; int bitLen = (len == 0 ? 0 : ((len - 1) << 5) + bitLengthForInt(mag[0])); int byteLen = (bitLen + 7) >>> 3; byte[] result = new byte[byteLen]; for (int i = byteLen - 1, bytesCopied = 4, intIndex = len - 1, nextInt = 0; i>=0; i--) { if (bytesCopied == 4) { nextInt = mag[intIndex--]; bytesCopied = 1; } else { nextInt >>>= 8; bytesCopied++; } result[i] = (byte)nextInt; } return result; } }
/** * Returns the mag array as an array of bytes. */ private byte[] magSerializedForm() { int len = mag.length; int bitLen = (len == 0 ? 0 : ((len - 1) << 5) + bitLengthForInt(mag[0])); int byteLen = (bitLen + 7) >>> 3; byte[] result = new byte[byteLen]; for (int i = byteLen - 1, bytesCopied = 4, intIndex = len - 1, nextInt = 0; i>=0; i--) { if (bytesCopied == 4) { nextInt = mag[intIndex--]; bytesCopied = 1; } else { nextInt >>>= 8; bytesCopied++; } result[i] = (byte)nextInt; } return result; } }
} else { int magBitLength = ((len - 1) << 5) + bitLengthForInt(mag[0]); if (signum < 0) {
} else { int magBitLength = ((len - 1) << 5) + bitLengthForInt(mag[0]); if (signum < 0) {
/** * Right shift this MutableBigInteger n bits. The MutableBigInteger is left * in normal form. */ void rightShift(int n) { if (intLen == 0) return; int nInts = n >>> 5; int nBits = n & 0x1F; this.intLen -= nInts; if (nBits == 0) return; int bitsInHighWord = BigInteger.bitLengthForInt(value[offset]); if (nBits >= bitsInHighWord) { this.primitiveLeftShift(32 - nBits); this.intLen--; } else { primitiveRightShift(nBits); } }
/** * Right shift this MutableBigInteger n bits. The MutableBigInteger is left * in normal form. */ void rightShift(int n) { if (intLen == 0) return; int nInts = n >>> 5; int nBits = n & 0x1F; this.intLen -= nInts; if (nBits == 0) return; int bitsInHighWord = BigInteger.bitLengthForInt(value[offset]); if (nBits >= bitsInHighWord) { this.primitiveLeftShift(32 - nBits); this.intLen--; } else { primitiveRightShift(nBits); } }
/** * Left shift int array a up to len by n bits. Returns the array that * results from the shift since space may have to be reallocated. */ private static int[] leftShift(int[] a, int len, int n) { int nInts = n >>> 5; int nBits = n&0x1F; int bitsInHighWord = bitLengthForInt(a[0]); // If shift can be done without recopy, do so if (n <= (32-bitsInHighWord)) { primitiveLeftShift(a, len, nBits); return a; } else { // Array must be resized if (nBits <= (32-bitsInHighWord)) { int result[] = new int[nInts+len]; for (int i=0; i<len; i++) result[i] = a[i]; primitiveLeftShift(result, result.length, nBits); return result; } else { int result[] = new int[nInts+len+1]; for (int i=0; i<len; i++) result[i] = a[i]; primitiveRightShift(result, result.length, 32 - nBits); return result; } } }
/** * Left shift int array a up to len by n bits. Returns the array that * results from the shift since space may have to be reallocated. */ private static int[] leftShift(int[] a, int len, int n) { int nInts = n >>> 5; int nBits = n&0x1F; int bitsInHighWord = bitLengthForInt(a[0]); // If shift can be done without recopy, do so if (n <= (32-bitsInHighWord)) { primitiveLeftShift(a, len, nBits); return a; } else { // Array must be resized if (nBits <= (32-bitsInHighWord)) { int result[] = new int[nInts+len]; for (int i=0; i<len; i++) result[i] = a[i]; primitiveLeftShift(result, result.length, nBits); return result; } else { int result[] = new int[nInts+len+1]; for (int i=0; i<len; i++) result[i] = a[i]; primitiveRightShift(result, result.length, 32 - nBits); return result; } } }
int nInts = n >>> 5; int nBits = n&0x1F; int bitsInHighWord = BigInteger.bitLengthForInt(value[offset]);
int nInts = n >>> 5; int nBits = n&0x1F; int bitsInHighWord = BigInteger.bitLengthForInt(value[offset]);