C# Class LCM.Util.BitConverter

Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from the meta data of System.BitConverter. This implementation allows for Endianness consideration. based on http://snipplr.com/view.php?codeview&id=15179, rewritten
ファイルを表示 Open project: mlab-upenn/arch-apex

Public Properties

Property Type Description
IsLittleEndian bool

Public Methods

Method Description
GetBytes ( double value ) : byte[]

Returns the specified double-precision floating point value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 8.

GetBytes ( float value ) : byte[]

Returns the specified single-precision floating point value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 4.

GetBytes ( int value ) : byte[]

Returns the specified 32-bit signed integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 4.

GetBytes ( long value ) : byte[]

Returns the specified 64-bit signed integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 8.

GetBytes ( short value ) : byte[]

Returns the specified 16-bit signed integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 2.

GetBytes ( uint value ) : byte[]

Returns the specified 32-bit unsigned integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 4.

GetBytes ( ulong value ) : byte[]

Returns the specified 64-bit unsigned integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 8.

GetBytes ( ushort value ) : byte[]

Returns the specified 16-bit unsigned integer value as an array of bytes. Parameters: value: The number to convert. Returns: An array of bytes with length 2.

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. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A double precision floating point number formed by eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToInt16 ( byte value, int startIndex ) : short

Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 16-bit signed integer formed by two bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex equals the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToInt32 ( byte value, int startIndex ) : int

Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 32-bit signed integer formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToInt64 ( byte value, int startIndex ) : long

Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 64-bit signed integer formed by eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

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. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A single-precision floating point number formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToUInt16 ( byte value, int startIndex ) : ushort

Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. Parameters: value: The array of bytes. startIndex: The starting position within value. Returns: A 16-bit unsigned integer formed by two bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex equals the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToUInt32 ( byte value, int startIndex ) : uint

Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 32-bit unsigned integer formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

ToUInt64 ( byte value, int startIndex ) : ulong

Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.

Method Details

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

GetBytes() public static method

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

ToDouble() public static method

Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A double precision floating point number formed by eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToDouble ( byte value, int startIndex ) : double
value byte
startIndex int
return double

ToInt16() public static method

Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 16-bit signed integer formed by two bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex equals the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToInt16 ( byte value, int startIndex ) : short
value byte
startIndex int
return short

ToInt32() public static method

Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 32-bit signed integer formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToInt32 ( byte value, int startIndex ) : int
value byte
startIndex int
return int

ToInt64() public static method

Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 64-bit signed integer formed by eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToInt64 ( byte value, int startIndex ) : long
value byte
startIndex int
return long

ToSingle() public static method

Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A single-precision floating point number formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToSingle ( byte value, int startIndex ) : float
value byte
startIndex int
return float

ToUInt16() public static method

Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. Parameters: value: The array of bytes. startIndex: The starting position within value. Returns: A 16-bit unsigned integer formed by two bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex equals the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToUInt16 ( byte value, int startIndex ) : ushort
value byte
startIndex int
return ushort

ToUInt32() public static method

Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 32-bit unsigned integer formed by four bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToUInt32 ( byte value, int startIndex ) : uint
value byte
startIndex int
return uint

ToUInt64() public static method

Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. Parameters: value: An array of bytes. startIndex: The starting position within value. Returns: A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1. System.ArgumentNullException: value is null. System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
public static ToUInt64 ( byte value, int startIndex ) : ulong
value byte
startIndex int
return ulong

Property Details

IsLittleEndian public_oe static_oe property

Indicates the byte order ("endianess") in which data is stored in this computer architecture.
public static bool IsLittleEndian
return bool