Java BigInteger Calculate writeBigInteger(ByteArrayOutputStream stream, BigInteger num)

Here you can find the source of writeBigInteger(ByteArrayOutputStream stream, BigInteger num)

Description

write Big Integer

License

Apache License

Declaration

private static void writeBigInteger(ByteArrayOutputStream stream, BigInteger num) throws IOException 

Method Source Code

//package com.java2s;
/*/*  ww  w. java 2 s  .  c  o  m*/
 * Copyright 2013-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.math.BigInteger;

public class Main {
    private static void writeBigInteger(ByteArrayOutputStream stream, BigInteger num) throws IOException {
        int length = num.toByteArray().length;
        byte[] data = new byte[4];
        data[0] = (byte) ((length >> 24) & 0xFF);
        data[1] = (byte) ((length >> 16) & 0xFF);
        data[2] = (byte) ((length >> 8) & 0xFF);
        data[3] = (byte) (length & 0xFF);
        stream.write(data);
        stream.write(num.toByteArray());
    }
}

Related

  1. unsignedLongToBigInteger(byte[] source)
  2. unsignedToBigInteger(long l)
  3. writeBigInteger(BigInteger integer, DataOutputStream out)
  4. writeBigInteger(BigInteger m, int n, OutputStream os)
  5. writeBigInteger(ByteArrayOutputStream baos, BigInteger bi)
  6. writeBigInteger(OutputStream output, BigInteger value)
  7. writeField(String tagName, BigInteger value, PrintWriter writer, int indent)
  8. writeLuposBigInteger(final BigInteger value, final int numberOfBits, final OutputStream os)
  9. writeMPI(BigInteger num, OutputStream out)