public class HexUtil
extends java.lang.Object
Unless otherwise stated, the conventions follow the rules outlined in the Java Language Specification.
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
biToHex(java.math.BigInteger bi)
Turn a BigInteger into a hex string.
|
static byte[] |
bitsToBytes(java.util.BitSet ba,
int size)
Pack the bits in ba into a byte[].
|
static java.lang.String |
bitsToHexString(java.util.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,
java.util.BitSet ba,
int maxSize)
Read bits from a byte array into a bitset
|
static java.lang.String |
bytesToHex(byte[] bs) |
static java.lang.String |
bytesToHex(byte[] bs,
int off,
int length)
Converts a byte array into a string of lower case hex chars.
|
static void |
bytesToHexAppend(byte[] bs,
int off,
int length,
java.lang.StringBuilder sb) |
static int |
countBytesForBits(int size) |
static void |
hexToBits(java.lang.String s,
java.util.BitSet ba,
int length)
Read a hex string of bits and write it into a bitset
|
static byte[] |
hexToBytes(java.lang.String s) |
static void |
hexToBytes(java.lang.String s,
byte[] out,
int off)
Converts a String of hex characters into an array of bytes.
|
static byte[] |
hexToBytes(java.lang.String s,
int off) |
static java.math.BigInteger |
readBigInteger(java.io.DataInputStream dis)
Read a (reasonably short) BigInteger from a DataInputStream
|
static java.lang.String |
toHexString(java.math.BigInteger i) |
static void |
writeBigInteger(java.math.BigInteger integer,
java.io.DataOutputStream out)
Write a (reasonably short) BigInteger to a stream.
|
public static final java.lang.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 void bytesToHexAppend(byte[] bs, int off, int length, java.lang.StringBuilder sb)
public static java.lang.String bytesToHex(byte[] bs)
public static byte[] hexToBytes(java.lang.String s)
public static byte[] hexToBytes(java.lang.String s, int off)
public static void hexToBytes(java.lang.String s, byte[] out, int off) throws java.lang.NumberFormatException, java.lang.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 arrayjava.lang.NumberFormatException
java.lang.IndexOutOfBoundsException
public static byte[] bitsToBytes(java.util.BitSet ba, int size)
ba
- : the BitSetsize
- : How many bits shall be taken into account starting from the LSB?public static java.lang.String bitsToHexString(java.util.BitSet ba, int size)
public static java.lang.String toHexString(java.math.BigInteger i)
public static int countBytesForBits(int size)
public static void bytesToBits(byte[] b, java.util.BitSet ba, int maxSize)
b
- the byte[] to read fromba
- the bitset to write topublic static void hexToBits(java.lang.String s, java.util.BitSet ba, int length)
s
- hex string of the stored bitsba
- the bitset to store the bits inlength
- the maximum number of bits to storepublic static void writeBigInteger(java.math.BigInteger integer, java.io.DataOutputStream out) throws java.io.IOException
integer
- the BigInteger to writeout
- the stream to write it tojava.io.IOException
public static java.math.BigInteger readBigInteger(java.io.DataInputStream dis) throws java.io.IOException
dis
- the stream to read fromjava.io.IOException
public static java.lang.String biToHex(java.math.BigInteger bi)