Class NumberUtils
Miscellaneuos utility methods for numbers manipulation.
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public abstract class NumberUtils
Methods
ChangeEndian(short)
Changes the endian of Int16 value.
Declaration
public static short ChangeEndian(short value)
Parameters
Type | Name | Description |
---|---|---|
short | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
short | Value with changed endian. |
ChangeEndian(int)
Changes the endian of Int32 value.
Declaration
public static int ChangeEndian(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
int | Value with changed endian. |
ChangeEndian(long)
Changes the endian of Int64 value.
Declaration
public static long ChangeEndian(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
long | Value with changed endian. |
ChangeEndian(ushort)
Changes the endian of UInt16 value.
Declaration
public static ushort ChangeEndian(ushort value)
Parameters
Type | Name | Description |
---|---|---|
ushort | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
ushort | Value with changed endian. |
ChangeEndian(uint)
Changes the endian of UInt32 value.
Declaration
public static uint ChangeEndian(uint value)
Parameters
Type | Name | Description |
---|---|---|
uint | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
uint | Value with changed endian. |
ChangeEndian(ulong)
Changes the endian of UInt64 value.
Declaration
public static ulong ChangeEndian(ulong value)
Parameters
Type | Name | Description |
---|---|---|
ulong | value | Value for which endian is being changed. |
Returns
Type | Description |
---|---|
ulong | Value with changed endian. |
DecimalToRawInt128(decimal)
Converts Decimal to unscaled RawInt128 representation - compatible with Java BigInteger type.
Declaration
public static RawInt128 DecimalToRawInt128(decimal value)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | Decimal value to convert. |
Returns
Type | Description |
---|---|
RawInt128 | Signed-byte array representing unscaled RawInt128 value. |
DoubleToInt64Bits(double)
Converts Double to its bits, which are stored in a Int64 instance.
Declaration
public static long DoubleToInt64Bits(double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | Value to convert to bits. |
Returns
Type | Description |
---|---|
long | Bits packed within an Int64 instance. |
EncodeDecimalBits(RawInt128)
Encode RawInt128 value provided to array of int values representing Decimal unscaled value bits.
Declaration
public static int[] EncodeDecimalBits(RawInt128 int128)
Parameters
Type | Name | Description |
---|---|---|
RawInt128 | int128 | RawInt128 value. |
Returns
Type | Description |
---|---|
int[] | Decimal unscaled value bits as array of int. |
GetRandom()
Obtain a Random object that can be used to get random values.
Declaration
public static Random GetRandom()
Returns
Type | Description |
---|---|
Random | A random number generator. |
GetScale(decimal)
Gets a scale of Decimal value.
Declaration
public static int GetScale(decimal value)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The Decimal value to get scale from. |
Returns
Type | Description |
---|---|
int | Scale of a Decimal. |
GetUnscaledValue(decimal)
Gets the unscaled value of Decimal value.
Declaration
public static decimal GetUnscaledValue(decimal value)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The Decimal value to get scale from. |
Returns
Type | Description |
---|---|
decimal | Decimal which is unscaled value of a Decimal. |
Int32BitsToSingle(int)
Converts bits which are stored in an Int32 instance into the Single object.
Declaration
public static float Int32BitsToSingle(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | Bits packed within an Int32 instance. |
Returns
Type | Description |
---|---|
float | Single value represented by the bits in
|
Int64BitsToDouble(long)
Converts bits which are stored in an Int64 instance into the Double object.
Declaration
public static double Int64BitsToDouble(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | Bits packed within an Int64 instance. |
Returns
Type | Description |
---|---|
double | Double value represented by the bits in
|
IntToByteArray(int)
Converts Int32 to its byte array.
Declaration
public static byte[] IntToByteArray(int number)
Parameters
Type | Name | Description |
---|---|---|
int | number | Value to convert to byte array. |
Returns
Type | Description |
---|---|
byte[] | Number packed within a Byte array. |
IsNumber(object)
Returns true if specified object is one of .NET supported numeric types:
- byte
- short
- int
- long
- double
- float
- decimal
Declaration
public static bool IsNumber(object num)
Parameters
Type | Name | Description |
---|---|---|
object | num | An object being tested. |
Returns
Type | Description |
---|---|
bool | true if |
ParseHex(char)
Return the integer value of a hexidecimal digit.
Declaration
public static int ParseHex(char ch)
Parameters
Type | Name | Description |
---|---|---|
char | ch | The hex character to evaluate. |
Returns
Type | Description |
---|---|
int | The integer value of the passed hex character. |
ParseHex(string)
Parse the passed string of hexidecimal characters into a binary value.
Declaration
public static byte[] ParseHex(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | The hex string to evaluate. |
Returns
Type | Description |
---|---|
byte[] | The byte array value of the passed hex string. |
Remarks
This implementation allows the passed string to be prefixed with "0x".
SingleToInt32Bits(float)
Converts Single to its bits, which are stored in a Int32 instance.
Declaration
public static int SingleToInt32Bits(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | Value to convert to bits. |
Returns
Type | Description |
---|---|
int | Bits packed within an Int32 instance. |
ToCrc(byte[])
Calculate a CRC32 value from a byte array.
Declaration
public static uint ToCrc(byte[] ab)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | An array of bytes. |
Returns
Type | Description |
---|---|
uint | The 32-bit CRC value. |
ToCrc(byte[], int, int)
Calculate a CRC32 value from a portion of a byte array.
Declaration
public static uint ToCrc(byte[] ab, int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | An array of bytes. |
int | of | The offset into the array. |
int | cb | The number of bytes to evaluate. |
Returns
Type | Description |
---|---|
uint | The 32-bit CRC value. |
ToCrc(byte[], int, int, uint)
Continue to calculate a CRC32 value from a portion of a byte array.
Declaration
public static uint ToCrc(byte[] ab, int of, int cb, uint crc)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | An array of bytes. |
int | of | The offset into the array. |
int | cb | The number of bytes to evaluate. |
uint | crc | The previous CRC value. |
Returns
Type | Description |
---|---|
uint | The 32-bit CRC value. |
ToHex(int)
Convert a byte to the hex sequence of 2 hex digits.
Declaration
public static string ToHex(int b)
Parameters
Type | Name | Description |
---|---|---|
int | b | The byte. |
Returns
Type | Description |
---|---|
string | The hex sequence. |
ToHexEscape(byte)
Convert a byte to a hex sequence of '0' + 'x' + 2 hex digits.
Declaration
public static string ToHexEscape(byte b)
Parameters
Type | Name | Description |
---|---|---|
byte | b | The byte. |
Returns
Type | Description |
---|---|
string | The hex sequence. |
ToHexEscape(byte[])
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.
Declaration
public static string ToHexEscape(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytes | The byte array. |
Returns
Type | Description |
---|---|
string | The hex sequence. |
ToHexEscape(byte[], int, int)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.
Declaration
public static string ToHexEscape(byte[] bytes, int offset, int bytesCount)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytes | The byte array. |
int | offset | The offset into array. |
int | bytesCount | The number of bytes to convert. |
Returns
Type | Description |
---|---|
string | The hex sequence. |
URShift(int, int)
Performs an unsigned bitwise right shift with the specified number.
Declaration
public static int URShift(int number, int bits)
Parameters
Type | Name | Description |
---|---|---|
int | number | Number to operate on. |
int | bits | Ammount of bits to shift. |
Returns
Type | Description |
---|---|
int | The resulting number from the shift operation. |
URShift(long, int)
Performs an unsigned bitwise right shift with the specified number.
Declaration
public static long URShift(long number, int bits)
Parameters
Type | Name | Description |
---|---|---|
long | number | Number to operate on. |
int | bits | Ammount of bits to shift. |
Returns
Type | Description |
---|---|
long | The resulting number from the shift operation. |