Java BigInteger Calculate writeBigInteger(BigInteger m, int n, OutputStream os)

Here you can find the source of writeBigInteger(BigInteger m, int n, OutputStream os)

Description

write Big Integer

License

Open Source License

Declaration

public static void writeBigInteger(BigInteger m, int n, OutputStream os) throws Exception 

Method Source Code


//package com.java2s;
import java.math.*;
import java.io.*;

public class Main {
    public static void writeBigInteger(BigInteger m, int n, OutputStream os) throws Exception {
        byte[] temp = new byte[n];
        BigInteger mask = BigInteger.valueOf(0xFF);

        for (int j = 0; j < n; j++) {
            temp[j] = (byte) m.and(mask).intValue();
            m = m.shiftRight(8);/*w  ww .ja  va2  s  .c  o  m*/
        }

        os.write(temp);
    }

    public static void writeBigInteger(BigInteger m, ObjectOutputStream oos) throws Exception {
        byte[] bytes = m.toByteArray();
        oos.writeInt(bytes.length);
        oos.write(bytes);
    }
}

Related

  1. uint64ToByteStreamLE(BigInteger val, OutputStream stream)
  2. unsignedBigIntergerToByteArray(BigInteger bigInteger)
  3. unsignedLongToBigInteger(byte[] source)
  4. unsignedToBigInteger(long l)
  5. writeBigInteger(BigInteger integer, DataOutputStream out)
  6. writeBigInteger(ByteArrayOutputStream baos, BigInteger bi)
  7. writeBigInteger(ByteArrayOutputStream stream, BigInteger num)
  8. writeBigInteger(OutputStream output, BigInteger value)
  9. writeField(String tagName, BigInteger value, PrintWriter writer, int indent)