Java BigInteger Calculate writeLuposBigInteger(final BigInteger value, final int numberOfBits, final OutputStream os)

Here you can find the source of writeLuposBigInteger(final BigInteger value, final int numberOfBits, final OutputStream os)

Description

writeLuposBigInteger.

License

Open Source License

Parameter

Parameter Description
value a java.math.BigInteger object.
numberOfBits a int.
os a java.io.OutputStream object.

Exception

Parameter Description

Declaration

public final static void writeLuposBigInteger(final BigInteger value,
        final int numberOfBits, final OutputStream os)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.IOException;

import java.io.OutputStream;
import java.math.BigInteger;

public class Main {
    /**//w w w.  j  a v  a  2  s  .  c o  m
     * <p>writeLuposBigInteger.</p>
     *
     * @param value a {@link java.math.BigInteger} object.
     * @param numberOfBits a int.
     * @param os a {@link java.io.OutputStream} object.
     * @throws java.io.IOException if any.
     */
    public final static void writeLuposBigInteger(final BigInteger value,
            final int numberOfBits, final OutputStream os)
            throws IOException {
        int remainingBits = numberOfBits;
        BigInteger remainingValue = value;
        final BigInteger BYTE = BigInteger.valueOf(256);
        while (remainingBits > 0) {
            final BigInteger[] result = remainingValue
                    .divideAndRemainder(BYTE);
            remainingValue = result[0];
            os.write((byte) result[1].intValue());
            remainingBits -= 8;
        }
    }
}

Related

  1. writeBigInteger(BigInteger m, int n, OutputStream os)
  2. writeBigInteger(ByteArrayOutputStream baos, BigInteger bi)
  3. writeBigInteger(ByteArrayOutputStream stream, BigInteger num)
  4. writeBigInteger(OutputStream output, BigInteger value)
  5. writeField(String tagName, BigInteger value, PrintWriter writer, int indent)
  6. writeMPI(BigInteger num, OutputStream out)