public class ByteUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static ByteOrder |
CPU_ENDIAN
CPU的字节序
|
static ByteOrder |
DEFAULT_ORDER |
| Constructor and Description |
|---|
ByteUtil() |
| Modifier and Type | Method and Description |
|---|---|
static double |
bytesToDouble(byte[] bytes)
byte数组转Double
默认以小端序转换 |
static double |
bytesToDouble(byte[] bytes,
ByteOrder byteOrder)
byte数组转double
自定义端序 |
static float |
bytesToFloat(byte[] bytes)
byte数组转float
默认以小端序转换 |
static float |
bytesToFloat(byte[] bytes,
ByteOrder byteOrder)
byte数组转float
自定义端序 |
static int |
bytesToInt(byte[] bytes)
byte[]转int值
默认以小端序转换 |
static int |
bytesToInt(byte[] bytes,
ByteOrder byteOrder)
byte[]转int值
自定义端序 |
static int |
bytesToInt(byte[] bytes,
int start,
ByteOrder byteOrder)
byte[]转int值
自定义端序 |
static long |
bytesToLong(byte[] bytes)
byte数组转long
默认以小端序转换 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static long |
bytesToLong(byte[] bytes,
ByteOrder byteOrder)
byte数组转long
自定义端序 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static long |
bytesToLong(byte[] bytes,
int start,
ByteOrder byteOrder)
byte数组转long
自定义端序 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static <T extends Number> |
bytesToNumber(byte[] bytes,
Class<T> targetClass,
ByteOrder byteOrder)
byte数组转换为指定类型数字
|
static short |
bytesToShort(byte[] bytes)
byte数组转short
默认以小端序转换 |
static short |
bytesToShort(byte[] bytes,
ByteOrder byteOrder)
byte数组转short
自定义端序 |
static short |
bytesToShort(byte[] bytes,
int start,
ByteOrder byteOrder)
byte数组转short
自定义端序 |
static int |
byteToUnsignedInt(byte byteValue)
byte转无符号int
|
static byte[] |
doubleToBytes(double doubleValue)
double转byte数组
默认以小端序转换 |
static byte[] |
doubleToBytes(double doubleValue,
ByteOrder byteOrder)
double转byte数组
自定义端序 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static byte[] |
floatToBytes(float floatValue)
float转byte数组,默认以小端序转换
|
static byte[] |
floatToBytes(float floatValue,
ByteOrder byteOrder)
float转byte数组,自定义端序
|
static byte |
intToByte(int intValue)
int转byte
|
static byte[] |
intToBytes(int intValue)
int转byte数组
默认以小端序转换 |
static byte[] |
intToBytes(int intValue,
ByteOrder byteOrder)
int转byte数组
自定义端序 |
static byte[] |
longToBytes(long longValue)
long转byte数组
默认以小端序转换 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static byte[] |
longToBytes(long longValue,
ByteOrder byteOrder)
long转byte数组
自定义端序 from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java |
static byte[] |
numberToBytes(Number number)
将
Number转换为 |
static byte[] |
numberToBytes(Number number,
ByteOrder byteOrder)
将
Number转换为 |
static byte[] |
shortToBytes(short shortValue)
short转byte数组
默认以小端序转换 |
static byte[] |
shortToBytes(short shortValue,
ByteOrder byteOrder)
short转byte数组
自定义端序 |
public static final ByteOrder DEFAULT_ORDER
public static final ByteOrder CPU_ENDIAN
public static byte intToByte(int intValue)
intValue - int值public static int byteToUnsignedInt(byte byteValue)
byteValue - byte值public static short bytesToShort(byte[] bytes)
bytes - byte数组public static short bytesToShort(byte[] bytes,
ByteOrder byteOrder)
bytes - byte数组,长度必须为2byteOrder - 端序public static short bytesToShort(byte[] bytes,
int start,
ByteOrder byteOrder)
bytes - byte数组,长度必须大于2start - 开始位置byteOrder - 端序public static byte[] shortToBytes(short shortValue)
shortValue - short值public static byte[] shortToBytes(short shortValue,
ByteOrder byteOrder)
shortValue - short值byteOrder - 端序public static int bytesToInt(byte[] bytes)
bytes - byte数组public static int bytesToInt(byte[] bytes,
ByteOrder byteOrder)
bytes - byte数组byteOrder - 端序public static int bytesToInt(byte[] bytes,
int start,
ByteOrder byteOrder)
bytes - byte数组start - 开始位置(包含)byteOrder - 端序public static byte[] intToBytes(int intValue)
intValue - int值public static byte[] intToBytes(int intValue,
ByteOrder byteOrder)
intValue - int值byteOrder - 端序public static byte[] longToBytes(long longValue)
longValue - long值public static byte[] longToBytes(long longValue,
ByteOrder byteOrder)
longValue - long值byteOrder - 端序public static long bytesToLong(byte[] bytes)
bytes - byte数组public static long bytesToLong(byte[] bytes,
ByteOrder byteOrder)
bytes - byte数组byteOrder - 端序public static long bytesToLong(byte[] bytes,
int start,
ByteOrder byteOrder)
bytes - byte数组start - 计算数组开始位置byteOrder - 端序public static byte[] floatToBytes(float floatValue)
floatValue - float值public static byte[] floatToBytes(float floatValue,
ByteOrder byteOrder)
floatValue - float值byteOrder - 端序public static float bytesToFloat(byte[] bytes)
bytes - byte数组public static float bytesToFloat(byte[] bytes,
ByteOrder byteOrder)
bytes - byte数组byteOrder - 端序public static byte[] doubleToBytes(double doubleValue)
doubleValue - double值public static byte[] doubleToBytes(double doubleValue,
ByteOrder byteOrder)
doubleValue - double值byteOrder - 端序public static double bytesToDouble(byte[] bytes)
bytes - byte数组public static double bytesToDouble(byte[] bytes,
ByteOrder byteOrder)
bytes - byte数组byteOrder - 端序public static byte[] numberToBytes(Number number)
Number转换为number - 数字public static byte[] numberToBytes(Number number, ByteOrder byteOrder)
Number转换为number - 数字byteOrder - 端序public static <T extends Number> T bytesToNumber(byte[] bytes, Class<T> targetClass, ByteOrder byteOrder) throws IllegalArgumentException
T - 数字类型bytes - byte数组targetClass - 目标数字类型byteOrder - 端序IllegalArgumentException - 不支持的数字类型,如用户自定义数字类型Copyright © 2025. All rights reserved.