|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--mars.util.Binary
Some utility methods for working with binary representations.
Constructor Summary | |
Binary()
|
Method Summary | |
static char |
binaryStringToHexDigit(java.lang.String value)
Translate String consisting of '1's and '0's into char equivalent of the corresponding hexadecimal digit. |
static java.lang.String |
binaryStringToHexString(java.lang.String value)
Translate String consisting of '1's and '0's into String equivalent of the corresponding hexadecimal value. |
static int |
binaryStringToInt(java.lang.String value)
Translate String consisting of '1's and '0's into an int value having that binary representation. |
static long |
binaryStringToLong(java.lang.String value)
Translate String consisting of '1's and '0's into a long value having that binary representation. |
static int |
bitValue(int value,
int bit)
Returns the bit value of the given bit position of the given int value. |
static int |
bitValue(long value,
int bit)
Returns the bit value of the given bit position of the given long value. |
static int |
clearBit(int value,
int bit)
Sets the specified bit of the specified value to 0, and returns the result. |
static int |
getByte(int value,
int bite)
Gets the specified byte of the specified value. |
static java.lang.String |
hexStringToBinaryString(java.lang.String value)
Translate String consisting of hexadecimal digits into String consisting of corresponding binary digits ('1's and '0's). |
static int |
highOrderLongToInt(long longValue)
Returns int representing the bit values of the high order 32 bits of given 64 bit long value. |
static java.lang.String |
intToBinaryString(int value)
Translate int value into a String consisting of '1's and '0's. |
static java.lang.String |
intToBinaryString(int value,
int length)
Translate int value into a String consisting of '1's and '0's. |
static java.lang.String |
intToHexString(int d)
Prefix a hexadecimal-indicating string "0x" to the string which is returned by the method "Integer.toHexString". |
static boolean |
isHex(java.lang.String v)
Parsing method to see if a string represents a hex number. |
static boolean |
isOctal(java.lang.String v)
Parsing method to see if a string represents an octal number. |
static java.lang.String |
longToBinaryString(long value)
Translate long value into a String consisting of '1's and '0's. |
static java.lang.String |
longToBinaryString(long value,
int length)
Translate long value into a String consisting of '1's and '0's. |
static int |
lowOrderLongToInt(long longValue)
Returns int representing the bit values of the low order 32 bits of given 64 bit long value. |
static int |
setBit(int value,
int bit)
Sets the specified bit of the specified value to 1, and returns the result. |
static int |
setByte(int value,
int bite,
int replace)
Sets the specified byte of the specified value to the low order 8 bits of specified replacement value, and returns the result. |
static int |
stringToInt(java.lang.String s)
Attempt to validate given string whose characters represent a 32 bit integer. |
static long |
stringToLong(java.lang.String s)
Attempt to validate given string whose characters represent a 64 bit long. |
static long |
twoIntsToLong(int highOrder,
int lowOrder)
Returns long (64 bit integer) combining the bit values of two given 32 bit integer values. |
static java.lang.String |
unsignedIntToIntString(int d)
Produce String equivalent of integer value interpreting it as an unsigned integer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Binary()
Method Detail |
public static java.lang.String intToBinaryString(int value, int length)
value
- The int value to convert.length
- The number of bit positions, starting at least significant, to process.
public static java.lang.String intToBinaryString(int value)
value
- The int value to convert.
public static java.lang.String longToBinaryString(long value, int length)
value
- The long value to convert.length
- The number of bit positions, starting at least significant, to process.
public static java.lang.String longToBinaryString(long value)
value
- The long value to convert.
public static int binaryStringToInt(java.lang.String value)
value
- The String value to convert.
public static long binaryStringToLong(java.lang.String value)
value
- The String value to convert.
public static java.lang.String binaryStringToHexString(java.lang.String value)
value
- The String value to convert.
public static java.lang.String hexStringToBinaryString(java.lang.String value)
value
- String containing '0', '1', ...'f'
characters which form hexadecimal. Letters may be either upper or lower case.
Works either with or without leading "Ox".
public static char binaryStringToHexDigit(java.lang.String value)
value
- The String value to convert.
public static java.lang.String intToHexString(int d)
d
- The int value to convert.
public static java.lang.String unsignedIntToIntString(int d)
d
- The int value to interpret.
public static int stringToInt(java.lang.String s) throws java.lang.NumberFormatException
s
- candidate string
java.lang.NumberFormatException
- if string cannot be translated into an intpublic static long stringToLong(java.lang.String s) throws java.lang.NumberFormatException
s
- candidate string
java.lang.NumberFormatException
- if string cannot be translated into a longpublic static int highOrderLongToInt(long longValue)
longValue
- The long value from which to extract bits.
public static int lowOrderLongToInt(long longValue)
longValue
- The long value from which to extract bits.
public static long twoIntsToLong(int highOrder, int lowOrder)
highOrder
- Integer to form the high-order 32 bits of result.lowOrder
- Integer to form the high-order 32 bits of result.
public static int bitValue(int value, int bit)
value
- The value to read the bit from.bit
- bit position in range 0 (least significant) to 31 (most)
public static int bitValue(long value, int bit)
value
- The value to read the bit from.bit
- bit position in range 0 (least significant) to 63 (most)
public static int setBit(int value, int bit)
value
- The value in which the bit is to be set.bit
- bit position in range 0 (least significant) to 31 (most)
public static int clearBit(int value, int bit)
value
- The value in which the bit is to be set.bit
- bit position in range 0 (least significant) to 31 (most)
public static int setByte(int value, int bite, int replace)
value
- The value in which the byte is to be set.bite
- byte position in range 0 (least significant) to 3 (most)replace
- value to place into that byte position - use low order 8 bits
public static int getByte(int value, int bite)
value
- The value in which the byte is to be retrieved.bite
- byte position in range 0 (least significant) to 3 (most)
public static boolean isHex(java.lang.String v)
v
- String containing numeric digits (could be decimal, octal, or hex)
public static boolean isOctal(java.lang.String v)
v
- String containing numeric digits (could be decimal, octal, or hex)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |