Java BigInteger to bigIntegerToBytes(final BigInteger bigInteger)

Here you can find the source of bigIntegerToBytes(final BigInteger bigInteger)

Description

Wandelt einen BigInteger in ein vorzeichenloses Byte-Array um.

License

Open Source License

Parameter

Parameter Description
bigInteger BigInteger

Return

byte-Array mit erstem Byte != 0

Declaration

public static byte[] bigIntegerToBytes(final BigInteger bigInteger) 

Method Source Code


//package com.java2s;
/*//w  ww  .  j ava 2s  . co m
 * Copyright 2016 by Kappich Systemberatung Aachen
 * 
 * This file is part of de.bsvrz.dav.daf.
 * 
 * de.bsvrz.dav.daf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * de.bsvrz.dav.daf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with de.bsvrz.dav.daf; If not, see <http://www.gnu.org/licenses/>.
    
 * Contact Information:
 * Kappich Systemberatung
 * Martin-Luther-Stra?e 14
 * 52062 Aachen, Germany
 * phone: +49 241 4090 436 
 * mail: <info@kappich.de>
 */

import java.math.BigInteger;

import java.util.Arrays;

public class Main {
    /**
     * Wandelt einen BigInteger in ein vorzeichenloses Byte-Array um.
     * @param bigInteger BigInteger
     * @return byte-Array mit erstem Byte != 0
     */
    public static byte[] bigIntegerToBytes(final BigInteger bigInteger) {
        byte[] bytes = bigInteger.toByteArray();
        if (bytes[0] == 0) {
            return Arrays.copyOfRange(bytes, 1, bytes.length);
        }
        return bytes;
    }
}

Related

  1. bigIntegerToBytes(BigInteger b, int numBytes)
  2. bigIntegerToBytes(BigInteger b, int numBytes)
  3. bigIntegerToBytes(BigInteger b, int numBytes)
  4. bigIntegerToBytes(BigInteger integer)
  5. bigIntegerToBytes(BigInteger n, byte[] data, int[] offset)
  6. bigIntegerToDigits(BigInteger n)
  7. BigIntegerToEightBytes(BigInteger value)
  8. bigIntegerToHex(final BigInteger bigInteger)
  9. bigIntegerToList(BigInteger number)