|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmars.util.Binary
public class Binary
Some utility methods for working with binary representations.
Constructor Summary | |
---|---|
Binary()
|
Method Summary | |
---|---|
static char |
binaryStringToHexDigit(String value)
Translate String consisting of '1's and '0's into char equivalent of the corresponding hexadecimal digit. |
static String |
binaryStringToHexString(String value)
Translate String consisting of '1's and '0's into String equivalent of the corresponding hexadecimal value. |
static int |
binaryStringToInt(String value)
Translate String consisting of '1's and '0's into an int value having that binary representation. |
static long |
binaryStringToLong(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 String |
hexStringToBinaryString(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 String |
intToAscii(int d)
Produce ASCII string equivalent of integer value, interpreting it as 4 one-byte characters. |
static String |
intToBinaryString(int value)
Translate int value into a String consisting of '1's and '0's. |
static String |
intToBinaryString(int value,
int length)
Translate int value into a String consisting of '1's and '0's. |
static String |
intToHalfHexString(int d)
Returns a 6 character string representing the 16-bit hexadecimal equivalent of the given integer value. |
static String |
intToHexString(int d)
Prefix a hexadecimal-indicating string "0x" to the string which is returned by the method "Integer.toHexString". |
static boolean |
isHex(String v)
Parsing method to see if a string represents a hex number. |
static boolean |
isOctal(String v)
Parsing method to see if a string represents an octal number. |
static String |
longToBinaryString(long value)
Translate long value into a String consisting of '1's and '0's. |
static String |
longToBinaryString(long value,
int length)
Translate long value into a String consisting of '1's and '0's. |
static String |
longToHexString(long value)
Prefix a hexadecimal-indicating string "0x" to the string equivalent to the hexadecimal value in the long parameter. |
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(String s)
Attempt to validate given string whose characters represent a 32 bit integer. |
static long |
stringToLong(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 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 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 String intToBinaryString(int value)
value
- The int value to convert.
public static 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 String longToBinaryString(long value)
value
- The long value to convert.
public static int binaryStringToInt(String value)
value
- The String value to convert.
public static long binaryStringToLong(String value)
value
- The String value to convert.
public static String binaryStringToHexString(String value)
value
- The String value to convert.
public static String hexStringToBinaryString(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(String value)
value
- The String value to convert.
public static String intToHexString(int d)
d
- The int value to convert.
public static String intToHalfHexString(int d)
d
- The int value to convert.
public static String longToHexString(long value)
value
- The long value to convert.
public static String unsignedIntToIntString(int d)
d
- The int value to interpret.
public static String intToAscii(int d)
d
- The int value to interpret
public static int stringToInt(String s) throws NumberFormatException
s
- candidate string
NumberFormatException
- if string cannot be translated into an intpublic static long stringToLong(String s) throws NumberFormatException
s
- candidate string
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(String v)
v
- String containing numeric digits (could be decimal, octal, or hex)
public static boolean isOctal(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 |