public class ArraySupport
extends java.lang.Object
主要功能:
- byte[] ↔ HEX 字符串互转
- Number 类型转 HEX 字符串
- HEX 字符串合法性校验
- 字节数组的按位读取、设置、清零
- 支持按位索引的快捷操作
线程安全:所有方法均为无状态实现,可安全并发调用。
| 构造器和说明 |
|---|
ArraySupport() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
bitCheck(byte[] bits,
int index)
return
true if bit specialized by index in byte array bits is 1,otherwise false |
static boolean |
bitCheck(java.lang.String hex,
int index)
return
true if bit specialized by index in HEX string
hex is 1, otherwise false return false if index is null or out of range |
static byte[] |
bitReset(byte[] bits,
int index)
set bit specialized by
index in byte array bits to 0 |
static byte[] |
bitSet(byte[] bits,
int index)
set bit specialized by
index in byte array bits to 1 |
static byte[] |
bitSet(byte[] bits,
int index,
boolean set1)
set bit specialized by
index in byte array bits to 0 if set1 is true,otherwise set to 0 |
static void |
copyToByteArray(java.lang.String hex,
byte[] dest)
将十六进制字符串转换为字节数组并拷贝到目标数组
如果 hex为null或dest为null,将抛出 IllegalArgumentException 异常拷贝长度取 hex转换后的字节数组长度与dest长度的较小值 |
static byte[] |
fromHex(java.lang.String input)
cast HEX string to byte array
|
static java.lang.String |
toHex(byte[] input)
cast byte array to HEX string
|
static java.lang.String |
toHex(java.lang.Number input)
cast integral Number to HEX string
|
static java.lang.String |
toHex(java.lang.Object input)
cast byte array or number to HEX string
|
public static final java.lang.String toHex(byte[] input)
input - public static final java.lang.String toHex(java.lang.Number input)
input - public static final java.lang.String toHex(java.lang.Object input)
input - public static final byte[] fromHex(java.lang.String input)
input - null if input is nullpublic static void copyToByteArray(java.lang.String hex,
byte[] dest)
hex为null或dest为null,IllegalArgumentException 异常hex转换后的字节数组长度与dest长度的较小值hex - 十六进制字符串dest - 目标字节数组public static final boolean bitCheck(byte[] bits,
int index)
true if bit specialized by index in byte array bits is 1,otherwise falsebits - index - public static final boolean bitCheck(java.lang.String hex,
int index)
true if bit specialized by index in HEX string
hex is 1, otherwise false false if index is null or out of rangehex - index - public static final byte[] bitSet(byte[] bits,
int index)
index in byte array bits to 1bits - index - bitspublic static final byte[] bitReset(byte[] bits,
int index)
index in byte array bits to 0bits - index - bitspublic static final byte[] bitSet(byte[] bits,
int index,
boolean set1)
index in byte array bits to 0 if set1 is true,otherwise set to 0bits - index - set1 - bitsCopyright © 2026. All Rights Reserved.