|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.util.Hex
Class Hex provides static methods for the conversion
of numeric types to hexadecimal strings and vice versa.
Class Hex cannot be instantiated.
| Field Summary | |
private static long |
low16bits
|
private static long |
low32bits
|
private static long |
low8bits
|
| Constructor Summary | |
private |
Hex()
Private constructor to prevent instantiation. |
| Method Summary | |
static String |
byteToHex(byte b)
Returns the 2-character hexadecimal String
for the given byte. |
static String |
doubleToHex(double d)
Returns the 16-character hexadecimal String
for the given double. |
static String |
floatToHex(float f)
Returns the 8-character hexadecimal String
for the given float. |
static byte |
hexToByte(String s)
If the given String s is a hexadecimal String
and contains at most 2 digits,
then the String is converted to a byte and returned. |
static double |
hexToDouble(String s)
If the given String s is a hexadecimal String
and contains exactly 16 digits,
then the String is converted to a double and returned. |
static float |
hexToFloat(String s)
If the given String s is a hexadecimal String
and contains exactly 8 digits,
then the String is converted to a float and returned. |
static int |
hexToInt(String s)
If the given String s is a hexadecimal String
and contains at most 8 digits,
then the String is converted to an int and returned. |
static long |
hexToLong(String s)
If the given String s is a hexadecimal String
and contains at most 16 digits,
then the String is converted to a long and returned. |
static long |
hexToLong(String s,
int maxdigits)
If the given String s is a hexadecimal String
and contains at most maxdigits,
then the String is converted to a long and returned. |
static short |
hexToShort(String s)
If the given String s is a hexadecimal String
and contains at most 4 digits,
then the String is converted to a short and returned. |
static String |
intToHex(int i)
Returns the 8-character hexadecimal String
for the given int. |
static boolean |
isHexDigit(char c)
Returns whether or not the given char is a hexadecimal digit (0 to 9, A to F, a to f). |
static boolean |
isHexString(String s)
Returns whether or not the given String contains only
hexadecimal digits (0 to 9, A to F, a to f). |
static String |
longToHex(long a)
Returns the 16-character hexadecimal String
for the given long. |
static String |
longToHex(long a,
int maxdigits)
Returns a hexadecimal string for the given long that contains the maxdigits trailing hexadecimal digits. |
static StringableFilter |
maskFilter(long mask)
Returns a Stringable filter that filters XNumber
objects to be those that have zero bits where the given mask has
one bits. |
static String |
shortToHex(short s)
Returns the 4-character hexadecimal String
for the given short. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final long low8bits
private static final long low16bits
private static final long low32bits
| Constructor Detail |
private Hex()
| Method Detail |
public static String byteToHex(byte b)
String
for the given byte.
b - the byte to convert
Stringpublic static String shortToHex(short s)
String
for the given short.
s - the short to convert
Stringpublic static String intToHex(int i)
String
for the given int.
i - the int to convert
Stringpublic static String longToHex(long a)
String
for the given long.
a - the long to convert
Stringpublic static String floatToHex(float f)
Returns the 8-character hexadecimal String
for the given float.
Uses Float.floatToRawIntBits internally.
f - the float to convert
Stringpublic static String doubleToHex(double d)
Returns the 16-character hexadecimal String
for the given double.
Uses Double.doubleToRawLongBits internally.
d - the double to convert
String
public static String longToHex(long a,
int maxdigits)
Returns a hexadecimal string for the given long that contains the maxdigits trailing hexadecimal digits.
This method is a helper method for the other methods in this class.
a - the long to convertmaxdigits - the number of trailing digits to provide
String with maxdigits digits
public static byte hexToByte(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains at most 2 digits,
then the String is converted to a byte and returned.
Throws a ParseException if the String is not a
hexadecimal String or its length is greater than 2.
s - the hexadecimal String
ParseException - if s is not hexadecimal with at most 2 digits
public static short hexToShort(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains at most 4 digits,
then the String is converted to a short and returned.
Throws a ParseException if the String is not a
hexadecimal String or its length is greater than 4.
s - the hexadecimal String
ParseException - if s is not hexadecimal with at most 4 digits
public static int hexToInt(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains at most 8 digits,
then the String is converted to an int and returned.
Throws a ParseException if the String is not a
hexadecimal String or its length is greater than 8.
s - the hexadecimal String
ParseException - if s is not hexadecimal with at most 8 digits
public static long hexToLong(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains at most 16 digits,
then the String is converted to a long and returned.
Throws a ParseException if the String is not a
hexadecimal String or its length is greater than 16.
s - the hexadecimal String
ParseException - if s is not hexadecimal with at most 16 digits
public static float hexToFloat(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains exactly 8 digits,
then the String is converted to a float and returned.
Uses Float.intBitsToFloat internally.
Throws a ParseException if the String is not a
hexadecimal String or its length is not exactly 8.
s - the hexadecimal String
ParseException - if s is not hexadecimal with exactly 8 digitshexToInt(String),
Float.intBitsToFloat(int)
public static double hexToDouble(String s)
throws ParseException
If the given String s is a hexadecimal String
and contains exactly 16 digits,
then the String is converted to a double and returned.
Uses Double.longBitsToDouble internally.
Throws a ParseException if the String is not a
hexadecimal String or its length is not exactly 16.
s - the hexadecimal String
ParseException - if s is not hexadecimal with exactly 16 digitshexToLong(String),
Double.longBitsToDouble(long)
public static long hexToLong(String s,
int maxdigits)
throws ParseException
If the given String s is a hexadecimal String
and contains at most maxdigits,
then the String is converted to a long and returned.
Throws a ParseException if the given String
is null or is not a hexadecimal String,
or if its length is greater than maxdigits,
or if maxdigits is greater than 16.
This method is a helper method for the other methods in this class.
s - the hexadecimal Stringmaxdigits - the limit on the length of s
ParseExceptionpublic static boolean isHexString(String s)
Returns whether or not the given String contains only
hexadecimal digits (0 to 9, A to F, a to f).
Returns false if the given String is null.
s - the String to test
String contains only hexadecimal digitspublic static boolean isHexDigit(char c)
c - the char to test
public static StringableFilter maskFilter(long mask)
Returns a Stringable filter that filters XNumber
objects to be those that have zero bits where the given mask has
one bits.
If the object is of integral type then it is tested as a long but with the high order bits set to zero if necessary prior to the testing.
If the object is of floating type then it is converted to raw bits with the high order bits set to zero if necessary prior to the testing.
mask - the mask that tests for zero bits in the data
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||