Package org.aoju.bus.core.toolkit
Class ByteKit
java.lang.Object
org.aoju.bus.core.toolkit.ByteKit
对数字和字节进行转换 假设数据存储是以大端模式存储的:
- byte: 字节类型 占8位二进制 00000000
- char: 字符类型 占2个字节 16位二进制 byte[0] byte[1]
- int : 整数类型 占4个字节 32位二进制 byte[0] byte[1] byte[2] byte[3]
- long: 长整数类型 占8个字节 64位二进制 byte[0] byte[1] byte[2] byte[3] byte[4] byte[5]
- long: 长整数类型 占8个字节 64位二进制 byte[0] byte[1] byte[2] byte[3] byte[4] byte[5] byte[6] byte[7]
- float: 浮点数(小数) 占4个字节 32位二进制 byte[0] byte[1] byte[2] byte[3]
- double: 双精度浮点数(小数) 占8个字节 64位二进制 byte[0] byte[1] byte[2] byte[3] byte[4]byte[5] byte[6] byte[7]
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringbcd(byte[] data, int from, int to) 解析 BCD 码static doublebytesToDouble(byte[] data, int off, boolean bigEndian) byte数组转double 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic doublebytesToDoubleBE(byte[] data, int off) byte数组转double 默认以:ByteOrder.BIG_ENDIANstatic doublebytesToDoubleLE(byte[] data, int off) byte数组转double 默认以:ByteOrder.LITTLE_ENDIANstatic floatbytesToFloat(byte[] data, int off, boolean bigEndian) byte数组转float 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic floatbytesToFloatBE(byte[] data, int off) byte数组转float 默认以:ByteOrder.BIG_ENDIANstatic floatbytesToFloatLE(byte[] data, int off) byte数组转float 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToInt(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic intbytesToInt(byte[] data, int start, ByteOrder byteOrder) byte[]转int值static intbytesToIntBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIANstatic intbytesToIntLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic longbytesToLong(byte[] data, int off, boolean bigEndian) byte数组转long 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic longbytesToLong(byte[] data, int start, ByteOrder byteOrder) byte数组转longstatic longbytesToLongBE(byte[] data, int off) byte数组转long 默认以:ByteOrder.BIG_ENDIANstatic longbytesToLongLE(byte[] data, int off) byte数组转long 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToShort(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic voidbytesToShort(byte[] data, short[] s, int off, int len, boolean bigEndian) byte数组处理 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic intbytesToShortBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToShortLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic voidbytesToShortLE(byte[] data, short[] s, int off, int len) byte数组处理 默认排序:ByteOrder.LITTLE_ENDIANstatic voidbytesToShortsBE(byte[] data, short[] s, int off, int len) byte数组处理 默认排序:ByteOrder.BIG_ENDIANstatic intbytesToTag(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic intbytesToTagBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIANstatic intbytesToTagLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToUShort(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANstatic intbytesToUShortBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToUShortLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIANstatic intbytesToVR(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIANstatic byte[]concat(byte[] buf1, byte[] buf2) 将两个字节数组连接到一个新的字节数组static intcountOf(byte[] data, byte target) 统计目标字节在字节数组中出现的次数static byte[]doubleToBytes(double data, byte[] bytes, int off, boolean bigEndian) double转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]doubleToBytesBE(double data, byte[] bytes, int off) double转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]doubleToBytesLE(double data, byte[] bytes, int off) double转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic byte[]floatToBytes(float data, byte[] bytes, int off, boolean bigEndian) float转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]floatToBytesBE(float data, byte[] bytes, int off) float转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]floatToBytesLE(float data, byte[] bytes, int off) float转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic <T extends Number>
Tbyte数组转换为指定类型数字static byte[]将Number转换为static bytegetByte(int data) int转bytestatic byte[]getBytes(char data) char转byte数组static byte[]getBytes(char[] data) char转byte数组static byte[]getBytes(double data) double转byte数组 默认以小端序转换static byte[]double转byte数组static byte[]getBytes(float data) float转byte数组static byte[]double转byte数组static byte[]getBytes(int data) int转byte数组 默认以小端序转换static byte[]getBytes(int... data) int转byte数组 默认以小端序转换static byte[]int转byte数组 自定义端序static byte[]getBytes(long data) long转byte数组 默认以小端序转换static byte[]long转byte数组static byte[]getBytes(short data) short转byte数组 默认以小端序转换static byte[]short转byte数组 自定义端序static byte[]将Number转换为byte数组static byte[]string转byte数组static byte[]string转byte数组static chargetChar(byte[] data) byte数组转charstatic doublegetDouble(byte[] data) byte数组转Double 默认以小端序转换static doublebyte数组转double 自定义端序static floatgetFloat(byte[] data) byte数组转Double 默认以小端序转换static floatbyte数组转double 自定义端序static intgetInt(byte data) byte转无符号intstatic intgetInt(byte[] data) byte[]转int值 默认以小端序转换static intbyte[]转int值 自定义端序static longgetLong(byte[] data) byte数组转longstatic longbyte数组转longstatic <T extends Number>
Tbyte数组转换为指定类型数字static shortgetShort(byte[] data) byte数组转short 默认以小端序转换static shortbyte数组转short 自定义端序static shortbyte数组转short 自定义端序static StringgetString(byte[] data) byte数组转stringstatic Stringbyte数组转stringstatic intindexOf(byte[] data, byte target, int from, int to) 寻找目标字节在字节数组中的下标static byte[]intToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]intToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]intToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic byte[]join(byte[]... data) 连接多个字节数组static byte[]join(byte data, byte[]... datas) 连接多个字节数组static byte[]longToBytes(long data, byte[] bytes, int off, boolean bigEndian) long转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]longToBytesBE(long data, byte[] bytes, int off) long转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]longToBytesLE(long data, byte[] bytes, int off) long转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic byte[]shortToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]shortToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]shortToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic byte[][]split(byte[] data, byte separator) 根据分隔符拆分字节数组static byte[][]split(byte[] data, int len) 拆分byte数组为几个等份(最后一份可能小于len)static byte[]subArray(byte[] data, int from) 截取子数组static byte[]subArray(byte[] data, int from, int to) 截取子数组static byte[]swapInts(byte[] data, int off, int len) 字符交换static byte[]swapLongs(byte[] data, int off, int len) 字符交换static byte[][]swapShorts(byte[][] data) 字符交换static byte[]swapShorts(byte[] data, int off, int len) 字符交换static byte[]tagToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIANstatic byte[]tagToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIANstatic byte[]tagToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIANstatic byte[]trim(byte[] data, byte empty) 首尾去掉空字符static byte[]trim(byte[] data, byte empty, int from, int to) 从 from 到 to 截取子串 并 首尾去掉空字符static intunsigned(byte data) 无符号整数static intxor(byte[] data) 异或值,返回
-
Constructor Details
-
ByteKit
public ByteKit()
-
-
Method Details
-
getByte
public static byte getByte(int data) int转byte- Parameters:
data- int值- Returns:
- the byte
-
getBytes
public static byte[] getBytes(int data) int转byte数组 默认以小端序转换- Parameters:
data- int值- Returns:
- the byte
-
getBytes
public static byte[] getBytes(int... data) int转byte数组 默认以小端序转换- Parameters:
data- int值- Returns:
- the byte
-
getBytes
int转byte数组 自定义端序- Parameters:
data- int值byteOrder- 端序- Returns:
- the byte
-
getBytes
public static byte[] getBytes(long data) long转byte数组 默认以小端序转换- Parameters:
data- long值- Returns:
- the byte
-
getBytes
long转byte数组- Parameters:
data- long值byteOrder- 端序- Returns:
- the byte
-
getBytes
public static byte[] getBytes(float data) float转byte数组- Parameters:
data- float值- Returns:
- the byte
-
getBytes
double转byte数组- Parameters:
data- double值byteOrder- 端序- Returns:
- the byte
-
getBytes
public static byte[] getBytes(double data) double转byte数组 默认以小端序转换- Parameters:
data- double值- Returns:
- the byte
-
getBytes
double转byte数组- Parameters:
data- double值byteOrder- 端序- Returns:
- the byte
-
getBytes
public static byte[] getBytes(short data) short转byte数组 默认以小端序转换- Parameters:
data- short值- Returns:
- the byte
-
getBytes
short转byte数组 自定义端序- Parameters:
data- short值byteOrder- 端序- Returns:
- the byte
-
getBytes
public static byte[] getBytes(char data) char转byte数组- Parameters:
data- char值- Returns:
- the byte
-
getBytes
public static byte[] getBytes(char[] data) char转byte数组- Parameters:
data- char值- Returns:
- the byte
-
getBytes
string转byte数组- Parameters:
data- string值- Returns:
- the byte
-
getBytes
-
getInt
public static int getInt(byte data) byte转无符号int- Parameters:
data- byte值- Returns:
- the int
-
getInt
public static int getInt(byte[] data) byte[]转int值 默认以小端序转换- Parameters:
data- byte数组- Returns:
- the int
-
getInt
byte[]转int值 自定义端序- Parameters:
data- byte数组byteOrder- 端序- Returns:
- the int
-
bytesToInt
byte[]转int值- Parameters:
data- byte数组start- 计算数组开始位置byteOrder- 端序- Returns:
- int值
-
getLong
public static long getLong(byte[] data) byte数组转long- Parameters:
data- byte数组- Returns:
- the long
-
getLong
byte数组转long- Parameters:
data- byte数组byteOrder- 端序- Returns:
- the long
-
bytesToLong
byte数组转long- Parameters:
data- byte数组start- 计算数组开始位置byteOrder- 端序- Returns:
- long值
-
getFloat
public static float getFloat(byte[] data) byte数组转Double 默认以小端序转换- Parameters:
data- byte数组- Returns:
- the float
-
getFloat
byte数组转double 自定义端序- Parameters:
data- byte数组byteOrder- 端序- Returns:
- the float
-
getDouble
public static double getDouble(byte[] data) byte数组转Double 默认以小端序转换- Parameters:
data- byte数组- Returns:
- the double
-
getDouble
byte数组转double 自定义端序- Parameters:
data- byte数组byteOrder- 端序- Returns:
- the double
-
getShort
public static short getShort(byte[] data) byte数组转short 默认以小端序转换- Parameters:
data- byte数组- Returns:
- the short
-
getShort
byte数组转short 自定义端序- Parameters:
bytes- byte数组,长度必须为2byteOrder- 端序- Returns:
- short值
-
getShort
byte数组转short 自定义端序- Parameters:
bytes- byte数组,长度必须大于2start- 开始位置byteOrder- 端序- Returns:
- short值
-
getChar
public static char getChar(byte[] data) byte数组转char- Parameters:
data- 字节数组- Returns:
- the char
-
getString
byte数组转string- Parameters:
data- 字节数组- Returns:
- the string
-
getString
-
getBytes
-
getNumber
byte数组转换为指定类型数字- Type Parameters:
T- 数字类型- Parameters:
bytes- byte数组targetClass- 目标数字类型- Returns:
- 转换后的数字
- Throws:
IllegalArgumentException- 不支持的数字类型,如用户自定义数字类型
-
get
-
get
byte数组转换为指定类型数字- Type Parameters:
T- 数字类型- Parameters:
bytes- byte数组targetClass- 目标数字类型byteOrder- 端序- Returns:
- 转换后的数字
- Throws:
IllegalArgumentException- 不支持的数字类型,如用户自定义数字类型
-
split
public static byte[][] split(byte[] data, byte separator) 根据分隔符拆分字节数组- Parameters:
data- 字节数组separator- 分隔符- Returns:
- the byte
-
split
public static byte[][] split(byte[] data, int len) 拆分byte数组为几个等份(最后一份可能小于len)- Parameters:
data- 数组len- 每个小节的长度- Returns:
- 拆分后的数组
-
subArray
public static byte[] subArray(byte[] data, int from) 截取子数组- Parameters:
data- 字节数组from- 开始下标(包含)- Returns:
- the byte
-
subArray
public static byte[] subArray(byte[] data, int from, int to) 截取子数组- Parameters:
data- 字节数组from- 开始下标(包含)to- 结束下标(不包含)- Returns:
- the byte
-
join
public static byte[] join(byte data, byte[]... datas) 连接多个字节数组- Parameters:
data- 连字符datas- 二维数组- Returns:
- the byte
-
join
public static byte[] join(byte[]... data) 连接多个字节数组- Parameters:
data- 二维数组- Returns:
- the byte
-
trim
public static byte[] trim(byte[] data, byte empty) 首尾去掉空字符- Parameters:
data- 字节数组empty- 空数组- Returns:
- the byte
-
trim
public static byte[] trim(byte[] data, byte empty, int from, int to) 从 from 到 to 截取子串 并 首尾去掉空字符- Parameters:
data- 字节数组empty- 空字节from- 开始下标(包含)to- 结束下标(不包含)- Returns:
- the byte
-
bytesToInt
public static int bytesToInt(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the int
-
bytesToIntBE
public static int bytesToIntBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToIntLE
public static int bytesToIntLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToShort
public static int bytesToShort(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the int
-
bytesToShort
public static void bytesToShort(byte[] data, short[] s, int off, int len, boolean bigEndian) byte数组处理 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- long值s- 字符off- 偏移量len- 字符长度bigEndian- 是否大字节序列
-
bytesToShortBE
public static int bytesToShortBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToShortLE
public static int bytesToShortLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToShortsBE
public static void bytesToShortsBE(byte[] data, short[] s, int off, int len) byte数组处理 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- double值s- 字符off- 偏移量len- 字符长度
-
bytesToShortLE
public static void bytesToShortLE(byte[] data, short[] s, int off, int len) byte数组处理 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- double值s- 字符off- 偏移量len- 字符长度
-
bytesToUShort
public static int bytesToUShort(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the int
-
bytesToUShortBE
public static int bytesToUShortBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToUShortLE
public static int bytesToUShortLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToFloat
public static float bytesToFloat(byte[] data, int off, boolean bigEndian) byte数组转float 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the float
-
bytesToFloatBE
public static float bytesToFloatBE(byte[] data, int off) byte数组转float 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the float
-
bytesToFloatLE
public static float bytesToFloatLE(byte[] data, int off) byte数组转float 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the float
-
bytesToLong
public static long bytesToLong(byte[] data, int off, boolean bigEndian) byte数组转long 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the long
-
bytesToLongBE
public static long bytesToLongBE(byte[] data, int off) byte数组转long 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the long
-
bytesToLongLE
public static long bytesToLongLE(byte[] data, int off) byte数组转long 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the long
-
bytesToDouble
public static double bytesToDouble(byte[] data, int off, boolean bigEndian) byte数组转double 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the double
-
bytesToDoubleBE
public static double bytesToDoubleBE(byte[] data, int off) byte数组转double 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the double
-
bytesToDoubleLE
public static double bytesToDoubleLE(byte[] data, int off) byte数组转double 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the double
-
bytesToVR
public static int bytesToVR(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToTag
public static int bytesToTag(byte[] data, int off, boolean bigEndian) byte数组转int 默认以:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量bigEndian- 是否大字节序列- Returns:
- the int
-
bytesToTagBE
public static int bytesToTagBE(byte[] data, int off) byte数组转int 默认以:ByteOrder.BIG_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
bytesToTagLE
public static int bytesToTagLE(byte[] data, int off) byte数组转int 默认以:ByteOrder.LITTLE_ENDIAN- Parameters:
data- byte数组off- 偏移量- Returns:
- the int
-
intToBytes
public static byte[] intToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- float值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
intToBytesBE
public static byte[] intToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
intToBytesLE
public static byte[] intToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
shortToBytes
public static byte[] shortToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
shortToBytesBE
public static byte[] shortToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
shortToBytesLE
public static byte[] shortToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
longToBytes
public static byte[] longToBytes(long data, byte[] bytes, int off, boolean bigEndian) long转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- long值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
longToBytesBE
public static byte[] longToBytesBE(long data, byte[] bytes, int off) long转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- long值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
longToBytesLE
public static byte[] longToBytesLE(long data, byte[] bytes, int off) long转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- long值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
floatToBytes
public static byte[] floatToBytes(float data, byte[] bytes, int off, boolean bigEndian) float转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- float值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
floatToBytesBE
public static byte[] floatToBytesBE(float data, byte[] bytes, int off) float转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- double值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
floatToBytesLE
public static byte[] floatToBytesLE(float data, byte[] bytes, int off) float转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- double值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
doubleToBytes
public static byte[] doubleToBytes(double data, byte[] bytes, int off, boolean bigEndian) double转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- double值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
doubleToBytesBE
public static byte[] doubleToBytesBE(double data, byte[] bytes, int off) double转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- double值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
doubleToBytesLE
public static byte[] doubleToBytesLE(double data, byte[] bytes, int off) double转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- double值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
tagToBytes
public static byte[] tagToBytes(int data, byte[] bytes, int off, boolean bigEndian) int转byte数组 排序:ByteOrder.BIG_ENDIANorByteOrder.LITTLE_ENDIAN- Parameters:
data- float值bytes- 目标字节off- 偏移量bigEndian- 是否大字节序列- Returns:
- the byte
-
tagToBytesBE
public static byte[] tagToBytesBE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.BIG_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
tagToBytesLE
public static byte[] tagToBytesLE(int data, byte[] bytes, int off) int转byte数组 默认排序:ByteOrder.LITTLE_ENDIAN- Parameters:
data- int值bytes- 目标字节off- 偏移量- Returns:
- the byte
-
swapInts
public static byte[] swapInts(byte[] data, int off, int len) 字符交换- Parameters:
data- byte值off- 偏移量len- 长度- Returns:
- the byte
-
swapLongs
public static byte[] swapLongs(byte[] data, int off, int len) 字符交换- Parameters:
data- byte值off- 偏移量len- 长度- Returns:
- the byte
-
swapShorts
public static byte[][] swapShorts(byte[][] data) 字符交换- Parameters:
data- byte值- Returns:
- the byte
-
swapShorts
public static byte[] swapShorts(byte[] data, int off, int len) 字符交换- Parameters:
data- byte值off- 偏移量len- 长度- Returns:
- the byte
-
indexOf
public static int indexOf(byte[] data, byte target, int from, int to) 寻找目标字节在字节数组中的下标- Parameters:
data- 字节数组target- 目标字节from- 检索开始下标(包含)to- 检索结束下标(不包含)- Returns:
- 找不到则返回-1
-
countOf
public static int countOf(byte[] data, byte target) 统计目标字节在字节数组中出现的次数- Parameters:
data- 字节数组target- 目标字节- Returns:
- the int
-
bcd
解析 BCD 码- Parameters:
data- 字节数组from- 开始下标(包含)to- 结束下标(不包含)- Returns:
- the string
-
unsigned
public static int unsigned(byte data) 无符号整数- Parameters:
data- 字节- Returns:
- the int
-
xor
public static int xor(byte[] data) 异或值,返回- Parameters:
data- 数组- Returns:
- 异或值
-
concat
public static byte[] concat(byte[] buf1, byte[] buf2) 将两个字节数组连接到一个新的字节数组- Parameters:
buf1- 字节数组buf2- 字节数组- Returns:
- the byte
-