提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将浮点转换为字节数组
//package com.nowjava; public class Main {// from nowjava.com - 时 代 Java public static void main(String[] argv) throws Exception { float f = 2.45678f; System.out.println(java.util.Arrays.toString(floatToByte(f))); } public static byte[] floatToByte(float f) { return toLH(Float.floatToRawIntBits(f)); } public static byte[] toLH(int n) { byte[] b = new byte[4]; b[0] = (byte) (n & 0xff); b[1] = (byte) (n >> 8 & 0xff);/* 来自 时 代 J a v a 公 众 号 - nowjava.com*