public final class Hex extends Object
Modifier and Type | Method and Description |
---|---|
static String |
bytesToASCIIString(byte[] data) |
static String |
bytesToHexString(byte[] text)
Converts a byte array to capitalized hexadecimal text.
|
static String |
bytesToHexString(byte[] text,
int numRow) |
static String |
bytesToHexString(byte[] text,
int offset,
int length) |
static String |
bytesToHexString(byte[] text,
int offset,
int length,
int numRow)
Converts part of a byte array to capitalized hexadecimal text.
|
static String |
bytesToPrettyString(byte[] data)
Gets a human readable hexadecimal representation of
data
with spaces. |
static String |
bytesToPrettyString(byte[] data,
int columns,
boolean useIndex,
int indexPadWidth,
String altIndex,
boolean useASCII)
Gets a human readable hexadecimal representation of
data
with spaces and newlines in columns columns. |
static String |
bytesToSpacedHexString(byte[] data)
Hexadecimal representation of
data with spaces between
individual bytes. |
static String |
byteToHexString(byte b)
Converts the byte
b to capitalized hexadecimal text. |
static byte |
hexStringToByte(String text)
Converts the hexadecimal string in
text to a byte. |
static byte[] |
hexStringToBytes(String text)
Converts the hexadecimal string in
text to
a byte array. |
static int |
hexStringToInt(String text)
Converts the hexadecimal string in
text to
an integer. |
static short |
hexStringToShort(String text)
Converts the hexadecimal string in
text to a short. |
static String |
intToHexString(int n)
Converts the integer
n to capitalized hexadecimal text. |
static String |
shortToHexString(short s)
Converts the short
s to capitalized hexadecimal text. |
static byte[][] |
split(byte[] src,
int width)
Splits the byte array
src into a number of byte arrays of
length width . |
static String |
toHexString(byte[] text)
Converts a byte array to capitalized hexadecimal text.
|
static String |
toHexString(byte[] text,
int numRow) |
public static String byteToHexString(byte b)
b
to capitalized hexadecimal text.
The result will have length 2 and only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.b
- the byte to convert.b
.public static String shortToHexString(short s)
s
to capitalized hexadecimal text.
The result will have length 4 and only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.s
- the short to convert.s
.public static String intToHexString(int n)
n
to capitalized hexadecimal text.
The result will have length 8 and only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.n
- the integer to convert.n
.public static String bytesToHexString(byte[] text)
text
and will only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.text
- The byte array to convert.text
.public static String bytesToHexString(byte[] text, int numRow)
public static String toHexString(byte[] text)
text
and will only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.text
- The byte array to convert.text
.public static String toHexString(byte[] text, int numRow)
public static String bytesToHexString(byte[] text, int offset, int length, int numRow)
offset
until (excluding)
index offset + length
.
The length of the resulting string will be twice the length
text
and will only contain the characters '0', '1',
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'.text
- the byte array to convert.offset
- where to start.length
- how many bytes to convert.numRow
- number of bytes to be put one in one row of outputtext
.public static String bytesToHexString(byte[] text, int offset, int length)
public static byte hexStringToByte(String text) throws NumberFormatException
text
to a byte.text
- the string to converttext
.NumberFormatException
- if text
does not contain
a valid hexadecimal byte representation.public static short hexStringToShort(String text) throws NumberFormatException
text
to a short.text
- the string to converttext
.NumberFormatException
- if text
does not contain
a valid hexadecimal short representation.public static int hexStringToInt(String text) throws NumberFormatException
text
to
an integer.text
- the string to converttext
.NumberFormatException
- if text
does not contain
a valid hexadecimal integer representation.public static byte[] hexStringToBytes(String text) throws NumberFormatException
text
to
a byte array. If text
has an odd number of
characters, a 0
is inserted at the beginning.text
- the string to convert.text
.NumberFormatException
- if text
does not contain
a valid hexadecimal string.public static String bytesToSpacedHexString(byte[] data)
data
with spaces between
individual bytes.data
- the byte array to print.data
.public static String bytesToASCIIString(byte[] data)
public static byte[][] split(byte[] src, int width)
src
into a number of byte arrays of
length width
. (Plus one of length less than width if
width
does not divide the length of src
.)src
- the byte array to split.width
- a positive number.public static String bytesToPrettyString(byte[] data)
data
with spaces.
Includes and index and ASCII representation.data
- the byte array to print.data
.public static String bytesToPrettyString(byte[] data, int columns, boolean useIndex, int indexPadWidth, String altIndex, boolean useASCII)
data
with spaces and newlines in columns
columns.
Will print an index before each line if useIndex
is
true
.
Will print an ASCII representation after each line if
useASCII
is true
.data
- the byte array to print.columns
- the number of bytes per line.useIndex
- a boolean indicating whether each line should be started
with an index.indexPadWidth
- the padding width for index.altIndex
- string to prefix if no index is used.useASCII
- a boolean indicating whether each line should be ended
with an ASCII representation of the bytes in that line.data
.Copyright © 2016. All rights reserved.