Java BigInteger Parse getBigIntegerArrayFromByteArray(byte[] buf)

Here you can find the source of getBigIntegerArrayFromByteArray(byte[] buf)

Description

Convert a byte[] into an instance of our value class.

License

Open Source License

Parameter

Parameter Description
buf byte array to be converted

Return

converted short array as object

Declaration

public static BigInteger[] getBigIntegerArrayFromByteArray(byte[] buf) 

Method Source Code

//package com.java2s;
/**********************************************************************
Copyright (c) 2004 Brendan de Beer and others. All rights reserved.
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/*from w w  w  .  j  ava 2s. co  m*/
    
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.
    
Contributors:
2004 Brendan de Beer - Initial contributor for conversion methods
2005 Erik Bengtson - refactor mapping
2005 Andy Jefferson - added Timestamp/String converters
...
**********************************************************************/

import java.math.BigInteger;

public class Main {
    /**
     * Convert a byte[] into an instance of our value class.
     *
     * @param buf byte array to be converted
     *
     * @return converted short array as object
     */
    public static BigInteger[] getBigIntegerArrayFromByteArray(byte[] buf) {
        long[] d = getLongArrayFromByteArray(buf);
        BigInteger[] a = new BigInteger[d.length];
        for (int i = 0; i < a.length; i++) {
            a[i] = BigInteger.valueOf(d[i]);
        }
        return a;
    }

    /**
     * Convert a byte[] into an instance of our value class.
     * @param buf byte array to be converted
     * @return converted long array as object
     */
    public static long[] getLongArrayFromByteArray(byte[] buf) {
        int n = buf.length / 8;
        long[] a = new long[n];
        int i = 0;
        int j = 0;

        for (; i < n;) {
            a[i++] = ((long) (buf[j++] & 0xFF) << 56) + ((long) (buf[j++] & 0xFF) << 48)
                    + ((long) (buf[j++] & 0xFF) << 40) + ((long) (buf[j++] & 0xFF) << 32)
                    + ((long) (buf[j++] & 0xFF) << 24) + ((buf[j++] & 0xFF) << 16) + ((buf[j++] & 0xFF) << 8)
                    + (buf[j++] & 0xFF);
        }

        return a;
    }
}

Related

  1. getBigInteger(byte[] payload, int offset, int length)
  2. getBigInteger(Console console, Function validator)
  3. getBigInteger(Number number)
  4. getBigInteger(Number value)
  5. getBigInteger(String value)
  6. getBigIntegerValue(final Integer value)
  7. getBinaryNumberInString(BigInteger integerNumber)
  8. toBigInteger(String bigInteger)
  9. toBigInteger(String s)