Here you can find the source of writeMPI(BigInteger num, OutputStream out)
public static void writeMPI(BigInteger num, OutputStream out) throws IOException
//package com.java2s; /* This code is part of Freenet. It is distributed under the GNU General * Public License, version 2 (or at your option any later version). See * http://www.gnu.org/ for further details of the GPL. */ import java.io.IOException; import java.io.OutputStream; import java.math.BigInteger; public class Main { public static void writeMPI(BigInteger num, OutputStream out) throws IOException { out.write(MPIbytes(num));/*from ww w. ja v a 2 s .co m*/ } public static byte[] MPIbytes(BigInteger num) { int len = num.bitLength(); byte[] bytes = new byte[2 + ((len + 8) >> 3)]; System.arraycopy(num.toByteArray(), 0, bytes, 2, bytes.length - 2); bytes[0] = (byte) (len >> 8); bytes[1] = (byte) len; return bytes; } }