public class HexUtil extends Object
Unless otherwise stated, the conventions follow the rules outlined in the Java Language Specification.
Modifier and Type | Method and Description |
---|---|
static byte[] |
bitsToBytes(BitSet ba,
int size)
Pack the bits in ba into a byte[].
|
static String |
bitsToHexString(BitSet ba,
int size)
Pack the bits in ba into a byte[] then convert that
to a hex string and return it.
|
static void |
bytesToBits(byte[] b,
BitSet ba,
int maxSize)
Read bits from a byte array into a bitset
|
static String |
bytesToHex(byte[] bs) |
static String |
bytesToHex(byte[] bs,
int off,
int length)
Converts a byte array into a string of upper case hex chars.
|
static void |
bytesToHexAppend(byte[] bs,
int off,
int length,
StringBuffer sb) |
static int |
countBytesForBits(int size) |
static void |
hexToBits(String s,
BitSet ba,
int length)
Read a hex string of bits and write it into a bitset
|
static byte[] |
hexToBytes(String s) |
static void |
hexToBytes(String s,
byte[] out,
int off)
Converts a String of hex characters into an array of bytes.
|
static byte[] |
hexToBytes(String s,
int off) |
public static final String bytesToHex(byte[] bs, int off, int length)
bs
- A byte arrayoff
- The index of the first byte to readlength
- The number of bytes to read.public static final void bytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb)
public static final String bytesToHex(byte[] bs)
public static final byte[] hexToBytes(String s)
public static final byte[] hexToBytes(String s, int off)
public static final void hexToBytes(String s, byte[] out, int off) throws NumberFormatException, IndexOutOfBoundsException
s
- A string of hex characters (upper case or lower) of even
length.out
- A byte array of length at least s.length()/2 + offoff
- The first byte to write of the arrayNumberFormatException
IndexOutOfBoundsException
public static final byte[] bitsToBytes(BitSet ba, int size)
public static final String bitsToHexString(BitSet ba, int size)
public static int countBytesForBits(int size)
public static void bytesToBits(byte[] b, BitSet ba, int maxSize)
b
- the byte[] to read fromba
- the bitset to write to