Java Array Scale expandToLength16(byte scaledValue[], final boolean isNegative)

Here you can find the source of expandToLength16(byte scaledValue[], final boolean isNegative)

Description

Converts BigInteger's byte representation containing a scaled magnitude to a fixed size 16 byte array and set the sign in the most significant byte's most significant bit.

License

Open Source License

Parameter

Parameter Description
scaledValue Scaled twos complement representation of the decimal
isNegative Determines whether the sign bit is set

Declaration

private static final byte[] expandToLength16(byte scaledValue[],
        final boolean isNegative) 

Method Source Code

//package com.java2s;
/* This file is part of VoltDB.
 * Copyright (C) 2008-2010 VoltDB L.L.C.
 *
 * VoltDB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version./*from  www  .  ja v  a2s .  co m*/
 *
 * VoltDB 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Converts BigInteger's byte representation containing a scaled magnitude to a fixed size 16 byte array
     * and set the sign in the most significant byte's most significant bit.
     * @param scaledValue Scaled twos complement representation of the decimal
     * @param isNegative Determines whether the sign bit is set
     * @return
     */
    private static final byte[] expandToLength16(byte scaledValue[],
            final boolean isNegative) {
        if (scaledValue.length == 16) {
            return scaledValue;
        }
        byte replacement[] = new byte[16];
        if (isNegative) {
            java.util.Arrays.fill(replacement, (byte) -1);
        }
        for (int ii = 15; 15 - ii < scaledValue.length; ii--) {
            replacement[ii] = scaledValue[ii
                    - (replacement.length - scaledValue.length)];
        }
        return replacement;
    }
}

Related

  1. arrayScale(final Double[] first, final double scale)
  2. minMaxScale(final double[] x)
  3. scale(double[][] as)
  4. scale(final double[] a, double scale)
  5. scaleMAD(double[] data)