Here you can find the source of byteArrayToBigInteger(final byte[] data)
Parameter | Description |
---|---|
data | The byte[] to be converted to BigInteger |
Parameter | Description |
---|---|
IllegalArgumentException | an exception |
public static BigInteger byteArrayToBigInteger(final byte[] data)
//package com.java2s; /**//from w w w. jav a 2 s. c o m * **************************************************************************** * Copyright (c) 2015, MasterCard International Incorporated and/or its * affiliates. All rights reserved. * <p/> * The contents of this file may only be used subject to the MasterCard * Mobile Payment SDK for MCBP and/or MasterCard Mobile MPP UI SDK * Materials License. * <p/> * Please refer to the file LICENSE.TXT for full details. * <p/> * TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS", WITHOUT * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NON INFRINGEMENT. TO THE EXTENT PERMITTED BY LAW, IN NO EVENT SHALL * MASTERCARD OR ITS AFFILIATES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * ***************************************************************************** */ import java.math.BigInteger; public class Main { /** * Convert a BCD byte[] to BigInteger * * @param data The byte[] to be converted to BigInteger * * @return A BigInteger built out of a BCD byte array * * @throws IllegalArgumentException * */ public static BigInteger byteArrayToBigInteger(final byte[] data) { StringBuilder stringBuilder = new StringBuilder(data.length * 2); for (final byte aData : data) { int digit = (aData & 0xF0) >> 4; if (digit < 0 || digit > 9) { throw new IllegalArgumentException("Invalid digit: " + digit); } stringBuilder.append((char) (digit + 0x30)); digit = aData & 0x0F; if (digit < 0 || digit > 9) { throw new IllegalArgumentException("Invalid digit: " + digit); } stringBuilder.append((char) (digit + 0x30)); } return new BigInteger(stringBuilder.toString(), 10); } }