Java BigInteger Calculate byte_size(BigInteger bi)

Here you can find the source of byte_size(BigInteger bi)

Description

BigInteger size in bytes.

License

Open Source License

Parameter

Parameter Description
bi a parameter

Return

the size in bytes of bi

Declaration

public static int byte_size(BigInteger bi) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License as

import java.math.BigInteger;

public class Main {
    /**//ww w  . j  a v  a 2s.com
     * BigInteger size in bytes. For {@link java.math.BigInteger#ZERO
     * BigInteger.ZERO} it returns 1.
     * Note that the value computed here might be different 
     * from 
     * {@link java.math.BigInteger#toByteArray BigInteger.toByteArray}.length
     * because the latter might add a leading zero byte. 
     *
     * @param bi
     * @return the size in bytes of {@code bi}
     */
    public static int byte_size(BigInteger bi) {
        int l = (bi.bitLength() + 7) / 8;
        return l == 0 ? 1 : l;
    }
}

Related

  1. areEqual(BigInteger[] a, BigInteger[] b)
  2. base128(BigInteger val)
  3. base62Encode(BigInteger number)
  4. bitArrayToUnsignedBigInteger(int[] bits)
  5. bitcoinValueToFriendlyString(BigInteger value)
  6. calculateGx(BigInteger p, BigInteger g, BigInteger x)
  7. calculateRx_(BigInteger Rx, BigInteger n)
  8. castToBigInteger(Object val)
  9. chop(BigInteger in, int bits)