Java Convert via ByteBuffer toFloatArray(int[] intArray)

Here you can find the source of toFloatArray(int[] intArray)

Description

to Float Array

License

Open Source License

Declaration

public static float[] toFloatArray(int[] intArray) 

Method Source Code


//package com.java2s;
/*//from  ww w .j  a  v a  2  s.  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 float[] toFloatArray(byte[] byteArray) {
        int times = Float.SIZE / Byte.SIZE;
        float[] floats = new float[byteArray.length / times];
        for (int i = 0; i < floats.length; i++) {
            floats[i] = ByteBuffer.wrap(byteArray, i * times, times).getFloat();
        }
        return floats;
    }

    public static float[] toFloatArray(int[] intArray) {
        float[] floats = new float[intArray.length];
        for (int i = 0; i < intArray.length; i++) {
            float value = Float.intBitsToFloat(intArray[i]);
            floats[i] = value;
        }

        return floats;
    }
}

Related

  1. toFile(URL url)
  2. toFile(URL url)
  3. toFiles(URL[] urls)
  4. toFloat(byte[] bytes)
  5. toFloat(final byte[] b)
  6. toFloatBytes(List datas)
  7. toGuidBytes(UUID theUuid)
  8. toGuidString(UUID uuid)
  9. toHex(byte[] bytes)