Here you can find the source of getBigIntegerArrayFromByteArray(byte[] buf)
Parameter | Description |
---|---|
buf | byte array to be converted |
public static BigInteger[] getBigIntegerArrayFromByteArray(byte[] buf)
//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; } }