Code example for BigInteger

Methods: bitLength, toByteArray

0
     
    public void encode( 
        BCPGOutputStream    out)
        throws IOException 
    { 
        int length = value.bitLength();
         
        out.write(length >> 8);
        out.write(length);
         
        byte[]    bytes = value.toByteArray();
         
        if (bytes[0] == 0)
        { 
            out.write(bytes, 1, bytes.length - 1);
        } 
        else 
        { 
            out.write(bytes, 0, bytes.length);
        } 
    }