|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.util.Hex
public abstract class Hex
Hexadecimal encoding and decoding methods.
Hexadecimal encoding, a.k.a. radix-16 encoding, is a form of encoding binary data as hexadecimal digits. (Each hexadecimal digit is 4 bits, providing 16 distinct binary values, hence the term hexadecimal or radix-16.) Two hexadecimal digits can be encoded in a single 8-bit byte.
Converting straight binary data (as a sequence of 8-bit bytes) into a hexadecimal (radix-16) representation is the process of converting each byte of the data into two hexadecimal digit characters.
Converting hexadecimal (radix-16) encoded data (as a sequence of 8-bit characters) back into straight binary data is the reverse operation, substituting each pair of hexadecimal digit characters with its corresponding 8-bit byte value.
For example, the 8-byte array:
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }is represented by the 16-character hexadecimal digit string:
"0123456789ABCDEF"
HexDump
Field Summary | |
---|---|
static int |
SERIES
Class revision number. |
Method Summary | |
---|---|
static byte[] |
decode(java.lang.String chars)
Decode hexadecimal characters into binary data. |
static int |
decode(java.lang.String chars,
byte[] dec,
int off,
int len)
Decode hexadecimal characters into binary data. |
static java.lang.String |
encode(byte[] data)
Encode binary data as hexadecimal characters. |
static java.lang.String |
encode(byte[] data,
int off,
int len)
Encode binary data as hexadecimal characters. |
static int |
fromHex(char ch)
Convert a hexadecimal (radix-16) digit character into its corresponding 4-bit binary value. |
static char |
toHex(int v)
Convert a 4-bit binary value into its corresponding hexadecimal (radix-16) printable ASCII digit character. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SERIES
Method Detail |
---|
public static final char toHex(int v)
v
- A 4-bit binary value in the range [0,15].
public static final int fromHex(char ch)
ch
- A hexadecimal (radix-16) ASCII digit character.
public static java.lang.String encode(byte[] data)
data
- Binary data, as an array of bytes (8-bit octets).
public static java.lang.String encode(byte[] data, int off, int len)
data
- Binary data, as an array of bytes (8-bit octets).off
- Index of the first byte (octet) within data to encode.len
- Number of bytes (octets) within data to encode.
public static byte[] decode(java.lang.String chars) throws java.text.ParseException
chars
- Printable ASCII string containing binary data encoded as radix-16
characters.
Whitespace characters (spaces, tabs, newlines) and control characters are
ignored.
java.text.ParseException
public static int decode(java.lang.String chars, byte[] dec, int off, int len) throws java.text.ParseException
chars
- Printable ASCII string containing binary data encoded as radix-16
characters.
Whitespace characters (spaces, tabs, newlines) and control characters are
ignored.dec
- Decoded byte (8-bit octet) array, which is filled with the decoded data.off
- Index of the first byte (8-bit octet) within dec to write to.len
- Number of bytes (8-bit octets) to write into dec.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |