Class BytesUtil
java.lang.Object
com.sure.tool.util.BytesUtil
字节数组工具类:基础类型与字节互转、拼接、切片、反转、十六进制,零依赖。
- Since:
- 0.2.0
- Author:
- suretool
-
Method Summary
Modifier and TypeMethodDescriptionstatic intbytesToInt(byte[] bytes) 4 字节转 int(大端)。static longbytesToLong(byte[] bytes) 8 字节转 long(大端)。static shortbytesToShort(byte[] bytes) 2 字节转 short(大端)。static byte[]concat(byte[]... arrays) 拼接多个字节数组。static byte[]intToBytes(int value) int 转 4 字节(大端)。static byte[]longToBytes(long value) long 转 8 字节(大端)。static byte[]reverse(byte[] bytes) 反转字节数组(返回新数组)。static byte[]shortToBytes(short value) short 转 2 字节(大端)。static byte[]slice(byte[] bytes, int from, int to) 切片(含 from 不含 to)。static byte[]字符串转字节数组(UTF-8)。static StringtoHex(byte[] bytes) 转小写十六进制字符串。static StringtoString(byte[] bytes) 字节数组转字符串(UTF-8)。
-
Method Details
-
longToBytes
public static byte[] longToBytes(long value) long 转 8 字节(大端)。- Parameters:
value- long 值- Returns:
- 8 字节
-
bytesToLong
public static long bytesToLong(byte[] bytes) 8 字节转 long(大端)。- Parameters:
bytes- 字节(至少 8 字节)- Returns:
- long 值
-
intToBytes
public static byte[] intToBytes(int value) int 转 4 字节(大端)。- Parameters:
value- int 值- Returns:
- 4 字节
-
bytesToInt
public static int bytesToInt(byte[] bytes) 4 字节转 int(大端)。- Parameters:
bytes- 字节(至少 4 字节)- Returns:
- int 值
-
shortToBytes
public static byte[] shortToBytes(short value) short 转 2 字节(大端)。- Parameters:
value- short 值- Returns:
- 2 字节
-
bytesToShort
public static short bytesToShort(byte[] bytes) 2 字节转 short(大端)。- Parameters:
bytes- 字节(至少 2 字节)- Returns:
- short 值
-
concat
public static byte[] concat(byte[]... arrays) 拼接多个字节数组。- Parameters:
arrays- 数组组- Returns:
- 拼接结果
-
slice
public static byte[] slice(byte[] bytes, int from, int to) 切片(含 from 不含 to)。- Parameters:
bytes- 原数组from- 起始(含)to- 结束(不含)- Returns:
- 切片
-
reverse
public static byte[] reverse(byte[] bytes) 反转字节数组(返回新数组)。- Parameters:
bytes- 原数组- Returns:
- 反转结果
-
toHex
-
toString
-
toBytes
-