@NotThreadSafe public class RadixUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
RadixUtils.NumberPattern
This class represents a number pattern in single radix
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNumberPattern(RadixUtils.NumberPattern pattern)
Add NumberPattern for further automatic radix recognition
|
static byte[] |
convertToNumber(String number,
int fromRadix)
Convert a integer number in some radix (stored in String) to binary
components in little endian.
|
static byte[] |
convertToNumber(String number,
int fromRadix,
int bytesCount)
Convert a integer number in some radix (stored in String) to binary
components in little endian.
|
static String |
convertToRadix(byte[] number,
int toRadix,
boolean littleEndian)
Converts number in any length to a number with specified radix.
|
String |
convertToRadix(String number,
int toRadix)
Converts number in any length to a number with specified radix.
|
static String |
convertToRadix(String number,
int fromRadix,
int toRadix)
Converts number in any length to a number with specified radix.
|
static String |
formatBinaryString(int number,
int length)
Get formatted binary string of given number.
|
static String |
formatBinaryString(int number,
int length,
int spacePerBits,
boolean spacesFromLeft)
Get formatted binary string of given number.
|
static String |
formatByteHexString(int byteNumber)
Get formatted string of a byte.
|
static String |
formatDwordHexString(int number)
Get formatted string of a dword.
|
static String |
formatWordHexString(int wordNumber)
Get formatted string of a word.
|
static String |
formatWordHexString(short upper,
short lower)
Get formatted string of a word.
|
static RadixUtils |
getInstance() |
int |
parseRadix(String number)
Parses a number in known radix into integer.
|
int |
parseRadix(String number,
int radix)
Parses a number in known radix into integer.
|
void |
setDefaults()
Clears all user-defined patterns
|
public static RadixUtils getInstance()
public void setDefaults()
public void addNumberPattern(RadixUtils.NumberPattern pattern)
pattern - NumberPattern instancepublic static String convertToRadix(byte[] number, int toRadix, boolean littleEndian)
number - any-length number. Array of number components stored in
little endian.toRadix - the radix of converted numberlittleEndian - If the number is in little endian (true), or big endian (false)public String convertToRadix(String number, int toRadix)
number - String representing number in hexa, octal or decadic radixtoRadix - target radix of the numberNumberFormatException - if the number is not in known formatpublic static String convertToRadix(String number, int fromRadix, int toRadix)
number - String representing number in any radixfromRadix - source radix of the numbertoRadix - target radix of the numberpublic static byte[] convertToNumber(String number, int fromRadix)
number - number stored as StringfromRadix - the radix of the numberpublic static byte[] convertToNumber(String number, int fromRadix, int bytesCount)
number - number stored as StringfromRadix - the radix of the numberbytesCount - number of bytes. If the results has fewer bytes, they will be appended from the left. If
it contains more bytes, they will be cut from the left (from MSB).public int parseRadix(String number) throws NumberFormatException
number - number in some known radixNumberFormatException - if the number is not in known formatpublic int parseRadix(String number, int radix) throws NumberFormatException
number - number in some known radixradix - radix of the number (known pattern must exist for parsing)NumberFormatException - if there is no pattern available for given radix or the number is unparseablepublic static String formatByteHexString(int byteNumber)
byteNumber - a number, assumed size is a bytepublic static String formatWordHexString(int wordNumber)
wordNumber - a number, assumed size is a word (2 bytes)public static String formatWordHexString(short upper, short lower)
upper - high order byte (high 8 bits)lower - low order byte (low 8bits)public static String formatDwordHexString(int number)
number - a number, assumed size is a double word (4 bytes)public static String formatBinaryString(int number, int length, int spacePerBits, boolean spacesFromLeft)
number - number to formatlength - resulting string length (number of bits)spacePerBits - number of space-separated bits. If <= 0 then bits are never separated with space.spacesFromLeft - whether the group of bits to be space-separated should be counted from left or from right sidepublic static String formatBinaryString(int number, int length)
number - number to formatlength - resulting string length (number of bits)Copyright © 2017. All rights reserved.