C# Class MiscUtil.Conversion.EndianBitConverter

Equivalent of System.BitConverter, but with either endianness.
Mostra file Open project: jadref/buffer_bci Class Usage Examples

Public Methods

Method Description
CopyBytes ( bool value, byte buffer, int index ) : void

Copies the specified Boolean value into the specified byte array, beginning at the specified index.

CopyBytes ( char value, byte buffer, int index ) : void

Copies the specified Unicode character value into the specified byte array, beginning at the specified index.

CopyBytes ( decimal value, byte buffer, int index ) : void

Copies the specified decimal value into the specified byte array, beginning at the specified index.

CopyBytes ( double value, byte buffer, int index ) : void

Copies the specified double-precision floating point value into the specified byte array, beginning at the specified index.

CopyBytes ( float value, byte buffer, int index ) : void

Copies the specified single-precision floating point value into the specified byte array, beginning at the specified index.

CopyBytes ( int value, byte buffer, int index ) : void

Copies the specified 32-bit signed integer value into the specified byte array, beginning at the specified index.

CopyBytes ( long value, byte buffer, int index ) : void

Copies the specified 64-bit signed integer value into the specified byte array, beginning at the specified index.

CopyBytes ( short value, byte buffer, int index ) : void

Copies the specified 16-bit signed integer value into the specified byte array, beginning at the specified index.

CopyBytes ( uint value, byte buffer, int index ) : void

Copies the specified 32-bit unsigned integer value into the specified byte array, beginning at the specified index.

CopyBytes ( ulong value, byte buffer, int index ) : void

Copies the specified 64-bit unsigned integer value into the specified byte array, beginning at the specified index.

CopyBytes ( ushort value, byte buffer, int index ) : void

Copies the specified 16-bit unsigned integer value into the specified byte array, beginning at the specified index.

DoubleToInt64Bits ( double value ) : long

Converts the specified double-precision floating point number to a 64-bit signed integer. Note: the endianness of this converter does not affect the returned value.

GetBytes ( bool value ) : byte[]

Returns the specified Boolean value as an array of bytes.

GetBytes ( char value ) : byte[]

Returns the specified Unicode character value as an array of bytes.

GetBytes ( decimal value ) : byte[]

Returns the specified decimal value as an array of bytes.

GetBytes ( double value ) : byte[]

Returns the specified double-precision floating point value as an array of bytes.

GetBytes ( float value ) : byte[]

Returns the specified single-precision floating point value as an array of bytes.

GetBytes ( int value ) : byte[]

Returns the specified 32-bit signed integer value as an array of bytes.

GetBytes ( long value ) : byte[]

Returns the specified 64-bit signed integer value as an array of bytes.

GetBytes ( short value ) : byte[]

Returns the specified 16-bit signed integer value as an array of bytes.

GetBytes ( uint value ) : byte[]

Returns the specified 32-bit unsigned integer value as an array of bytes.

GetBytes ( ulong value ) : byte[]

Returns the specified 64-bit unsigned integer value as an array of bytes.

GetBytes ( ushort value ) : byte[]

Returns the specified 16-bit unsigned integer value as an array of bytes.

Int32BitsToSingle ( int value ) : float

Converts the specified 32-bit signed integer to a single-precision floating point number. Note: the endianness of this converter does not affect the returned value.

Int64BitsToDouble ( long value ) : double

Converts the specified 64-bit signed integer to a double-precision floating point number. Note: the endianness of this converter does not affect the returned value.

IsLittleEndian ( ) : bool

Indicates the byte order ("endianess") in which data is converted using this class.

Different computer architectures store data using different byte orders. "Big-endian" means the most significant byte is on the left end of a word. "Little-endian" means the most significant byte is on the right end of a word.

SingleToInt32Bits ( float value ) : int

Converts the specified single-precision floating point number to a 32-bit signed integer. Note: the endianness of this converter does not affect the returned value.

ToBoolean ( byte value, int startIndex ) : bool

Returns a Boolean value converted from one byte at a specified position in a byte array.

ToChar ( byte value, int startIndex ) : char

Returns a Unicode character converted from two bytes at a specified position in a byte array.

ToDecimal ( byte value, int startIndex ) : decimal

Returns a decimal value converted from sixteen bytes at a specified position in a byte array.

ToDouble ( byte value, int startIndex ) : double

Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.

ToInt16 ( byte value, int startIndex ) : short

Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.

ToInt32 ( byte value, int startIndex ) : int

Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.

ToInt64 ( byte value, int startIndex ) : long

Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.

ToSingle ( byte value, int startIndex ) : float

Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.

ToString ( byte value ) : string

Returns a String converted from the elements of a byte array.

All the elements of value are converted.

ToString ( byte value, int startIndex ) : string

Returns a String converted from the elements of a byte array starting at a specified array position.

The elements from array position startIndex to the end of the array are converted.

ToString ( byte value, int startIndex, int length ) : string

Returns a String converted from a specified number of bytes at a specified position in a byte array.

The length elements from array position startIndex are converted.

ToUInt16 ( byte value, int startIndex ) : ushort

Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.

ToUInt32 ( byte value, int startIndex ) : uint

Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.

ToUInt64 ( byte value, int startIndex ) : ulong

Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.

Protected Methods

Method Description
CopyBytesImpl ( long value, int bytes, byte buffer, int index ) : void

Copies the given number of bytes from the least-specific end of the specified value into the specified byte array, beginning at the specified index. This must be implemented in concrete derived classes, but the implementation may assume that the value will fit into the buffer.

FromBytes ( byte value, int startIndex, int bytesToConvert ) : long

Convert the given number of bytes from the given array, from the given start position, into a long, using the bytes as the least significant part of the long. By the time this is called, the arguments have been checked for validity.

Private Methods

Method Description
CheckByteArgument ( byte value, int startIndex, int bytesRequired ) : void

Checks the given argument for validity.

CheckedFromBytes ( byte value, int startIndex, int bytesToConvert ) : long

Checks the arguments for validity before calling FromBytes (which can therefore assume the arguments are valid).

CopyBytes ( long value, int bytes, byte buffer, int index ) : void

Copies the given number of bytes from the least-specific end of the specified value into the specified byte array, beginning at the specified index. This is used to implement the other CopyBytes methods.

GetBytes ( long value, int bytes ) : byte[]

Returns an array with the given number of bytes formed from the least significant bytes of the specified value. This is used to implement the other GetBytes methods.

Method Details

CopyBytes() public method

Copies the specified Boolean value into the specified byte array, beginning at the specified index.
public CopyBytes ( bool value, byte buffer, int index ) : void
value bool A Boolean value.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified Unicode character value into the specified byte array, beginning at the specified index.
public CopyBytes ( char value, byte buffer, int index ) : void
value char A character to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified decimal value into the specified byte array, beginning at the specified index.
public CopyBytes ( decimal value, byte buffer, int index ) : void
value decimal A character to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified double-precision floating point value into the specified byte array, beginning at the specified index.
public CopyBytes ( double value, byte buffer, int index ) : void
value double The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified single-precision floating point value into the specified byte array, beginning at the specified index.
public CopyBytes ( float value, byte buffer, int index ) : void
value float The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 32-bit signed integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( int value, byte buffer, int index ) : void
value int The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 64-bit signed integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( long value, byte buffer, int index ) : void
value long The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 16-bit signed integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( short value, byte buffer, int index ) : void
value short The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 32-bit unsigned integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( uint value, byte buffer, int index ) : void
value uint The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 64-bit unsigned integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( ulong value, byte buffer, int index ) : void
value ulong The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytes() public method

Copies the specified 16-bit unsigned integer value into the specified byte array, beginning at the specified index.
public CopyBytes ( ushort value, byte buffer, int index ) : void
value ushort The number to convert.
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

CopyBytesImpl() protected abstract method

Copies the given number of bytes from the least-specific end of the specified value into the specified byte array, beginning at the specified index. This must be implemented in concrete derived classes, but the implementation may assume that the value will fit into the buffer.
protected abstract CopyBytesImpl ( long value, int bytes, byte buffer, int index ) : void
value long The value to copy bytes for
bytes int The number of significant bytes to copy
buffer byte The byte array to copy the bytes into
index int The first index into the array to copy the bytes into
return void

DoubleToInt64Bits() public method

Converts the specified double-precision floating point number to a 64-bit signed integer. Note: the endianness of this converter does not affect the returned value.
public DoubleToInt64Bits ( double value ) : long
value double The number to convert.
return long

FromBytes() protected abstract method

Convert the given number of bytes from the given array, from the given start position, into a long, using the bytes as the least significant part of the long. By the time this is called, the arguments have been checked for validity.
protected abstract FromBytes ( byte value, int startIndex, int bytesToConvert ) : long
value byte The bytes to convert
startIndex int The index of the first byte to convert
bytesToConvert int The number of bytes to use in the conversion
return long

GetBytes() public method

Returns the specified Boolean value as an array of bytes.
public GetBytes ( bool value ) : byte[]
value bool A Boolean value.
return byte[]

GetBytes() public method

Returns the specified Unicode character value as an array of bytes.
public GetBytes ( char value ) : byte[]
value char A character to convert.
return byte[]

GetBytes() public method

Returns the specified decimal value as an array of bytes.
public GetBytes ( decimal value ) : byte[]
value decimal The number to convert.
return byte[]

GetBytes() public method

Returns the specified double-precision floating point value as an array of bytes.
public GetBytes ( double value ) : byte[]
value double The number to convert.
return byte[]

GetBytes() public method

Returns the specified single-precision floating point value as an array of bytes.
public GetBytes ( float value ) : byte[]
value float The number to convert.
return byte[]

GetBytes() public method

Returns the specified 32-bit signed integer value as an array of bytes.
public GetBytes ( int value ) : byte[]
value int The number to convert.
return byte[]

GetBytes() public method

Returns the specified 64-bit signed integer value as an array of bytes.
public GetBytes ( long value ) : byte[]
value long The number to convert.
return byte[]

GetBytes() public method

Returns the specified 16-bit signed integer value as an array of bytes.
public GetBytes ( short value ) : byte[]
value short The number to convert.
return byte[]

GetBytes() public method

Returns the specified 32-bit unsigned integer value as an array of bytes.
public GetBytes ( uint value ) : byte[]
value uint The number to convert.
return byte[]

GetBytes() public method

Returns the specified 64-bit unsigned integer value as an array of bytes.
public GetBytes ( ulong value ) : byte[]
value ulong The number to convert.
return byte[]

GetBytes() public method

Returns the specified 16-bit unsigned integer value as an array of bytes.
public GetBytes ( ushort value ) : byte[]
value ushort The number to convert.
return byte[]

Int32BitsToSingle() public method

Converts the specified 32-bit signed integer to a single-precision floating point number. Note: the endianness of this converter does not affect the returned value.
public Int32BitsToSingle ( int value ) : float
value int The number to convert.
return float

Int64BitsToDouble() public method

Converts the specified 64-bit signed integer to a double-precision floating point number. Note: the endianness of this converter does not affect the returned value.
public Int64BitsToDouble ( long value ) : double
value long The number to convert.
return double

IsLittleEndian() public abstract method

Indicates the byte order ("endianess") in which data is converted using this class.
Different computer architectures store data using different byte orders. "Big-endian" means the most significant byte is on the left end of a word. "Little-endian" means the most significant byte is on the right end of a word.
public abstract IsLittleEndian ( ) : bool
return bool

SingleToInt32Bits() public method

Converts the specified single-precision floating point number to a 32-bit signed integer. Note: the endianness of this converter does not affect the returned value.
public SingleToInt32Bits ( float value ) : int
value float The number to convert.
return int

ToBoolean() public method

Returns a Boolean value converted from one byte at a specified position in a byte array.
public ToBoolean ( byte value, int startIndex ) : bool
value byte An array of bytes.
startIndex int The starting position within value.
return bool

ToChar() public method

Returns a Unicode character converted from two bytes at a specified position in a byte array.
public ToChar ( byte value, int startIndex ) : char
value byte An array of bytes.
startIndex int The starting position within value.
return char

ToDecimal() public method

Returns a decimal value converted from sixteen bytes at a specified position in a byte array.
public ToDecimal ( byte value, int startIndex ) : decimal
value byte An array of bytes.
startIndex int The starting position within value.
return decimal

ToDouble() public method

Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
public ToDouble ( byte value, int startIndex ) : double
value byte An array of bytes.
startIndex int The starting position within value.
return double

ToInt16() public method

Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
public ToInt16 ( byte value, int startIndex ) : short
value byte An array of bytes.
startIndex int The starting position within value.
return short

ToInt32() public method

Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
public ToInt32 ( byte value, int startIndex ) : int
value byte An array of bytes.
startIndex int The starting position within value.
return int

ToInt64() public method

Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
public ToInt64 ( byte value, int startIndex ) : long
value byte An array of bytes.
startIndex int The starting position within value.
return long

ToSingle() public method

Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
public ToSingle ( byte value, int startIndex ) : float
value byte An array of bytes.
startIndex int The starting position within value.
return float

ToString() public static method

Returns a String converted from the elements of a byte array.
All the elements of value are converted.
public static ToString ( byte value ) : string
value byte An array of bytes.
return string

ToString() public static method

Returns a String converted from the elements of a byte array starting at a specified array position.
The elements from array position startIndex to the end of the array are converted.
public static ToString ( byte value, int startIndex ) : string
value byte An array of bytes.
startIndex int The starting position within value.
return string

ToString() public static method

Returns a String converted from a specified number of bytes at a specified position in a byte array.
The length elements from array position startIndex are converted.
public static ToString ( byte value, int startIndex, int length ) : string
value byte An array of bytes.
startIndex int The starting position within value.
length int The number of bytes to convert.
return string

ToUInt16() public method

Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
public ToUInt16 ( byte value, int startIndex ) : ushort
value byte An array of bytes.
startIndex int The starting position within value.
return ushort

ToUInt32() public method

Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
public ToUInt32 ( byte value, int startIndex ) : uint
value byte An array of bytes.
startIndex int The starting position within value.
return uint

ToUInt64() public method

Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
public ToUInt64 ( byte value, int startIndex ) : ulong
value byte An array of bytes.
startIndex int The starting position within value.
return ulong