Java Convert via ByteBuffer toIntArray(float[] floatArray)

Here you can find the source of toIntArray(float[] floatArray)

Description

to Int Array

License

Open Source License

Declaration

public static int[] toIntArray(float[] floatArray) 

Method Source Code


//package com.java2s;
/*//  w  ww.  ja  v  a2s.  c  o  m
 * #%L
 * Ice-9 Tickerplant - Server
 * %%
 * Copyright (C) 2014 - 2015 Snowfall Systems, Inc.
 * %%
 * This file is part of PortfolioEffect Quant Client.
 * 
 * PortfolioEffect Quant Client 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.
 * 
 * PortfolioEffect Quant Client 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 PortfolioEffect Quant Client. If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import java.nio.ByteBuffer;

public class Main {
    public static int[] toIntArray(byte[] byteArray) {
        int times = Integer.SIZE / Byte.SIZE;
        int[] ints = new int[byteArray.length / times];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = ByteBuffer.wrap(byteArray, i * times, times).getInt();
        }
        return ints;
    }

    public static int[] toIntArray(float[] floatArray) {
        int[] ints = new int[floatArray.length];
        for (int i = 0; i < floatArray.length; i++) {
            int bits = Float.floatToIntBits(floatArray[i]);
            ints[i] = bits;
        }

        return ints;
    }

    public static int[] toIntArray(long[] longArray) {
        int[] ints = new int[longArray.length * 2];
        for (int i = 0, j = 0; i < longArray.length; i++, j += 2) {

            int x = (int) (longArray[i] >> 32);
            int y = (int) longArray[i];
            ints[i] = x;
            ints[i + longArray.length] = y;

        }

        return ints;
    }

    public static int[] toIntArray(double[] doubleArray) {
        int[] ints = new int[doubleArray.length];
        for (int i = 0; i < doubleArray.length; i++) {
            int bits = Float.floatToIntBits((float) doubleArray[i]);
            ints[i] = bits;
        }

        return ints;
    }
}

Related

  1. toInt(final byte lowOrderByte, final byte highOrderByte)
  2. toInt(InetAddress address)
  3. toIntArray(byte[] byteArray)
  4. toIntArray(byte[] byteArray)
  5. toIntArray(final byte[] byteArray)
  6. toIntBuffer(int[] array)
  7. toIntFromByteArray(byte[] byteArray)
  8. toLittleEndian(int value)
  9. toLMBCS(final String value)