集册 Java实例教程 将浮点转换为长度为4的字节数组。

将浮点转换为长度为4的字节数组。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

349
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将浮点转换为长度为4的字节数组。


//package com.nowjava;

/* 
*来 自
 N o w  J a v a  .   c o m
*/

import java.nio.ByteBuffer;


public class Main {

    public static void main(String[] argv) throws Exception {

        float f = 2.45678f;

        System.out.println(java.util.Arrays.toString(floatToByteArray(f)));

    }


    /**

     * Converts a float to a byte array with a length of 4.

     * @param f - The float.

     * @return The byte array.

     */

    public static byte[] fl
展开阅读全文