mscorlib(4.0.0.0) API with additions
System.BitConverter Class Reference

Converts base data types to an array of bytes, and an array of bytes to base data types. More...

Static Public Member Functions

static byte [] GetBytes (bool value)
 Returns the specified Boolean value as a byte array. More...
 
static byte [] GetBytes (char value)
 Returns the specified Unicode character value as an array of bytes. More...
 
static unsafe byte [] GetBytes (short value)
 Returns the specified 16-bit signed integer value as an array of bytes. More...
 
static unsafe byte [] GetBytes (int value)
 Returns the specified 32-bit signed integer value as an array of bytes. More...
 
static unsafe byte [] GetBytes (long value)
 Returns the specified 64-bit signed integer value as an array of bytes. More...
 
static byte [] GetBytes (ushort value)
 Returns the specified 16-bit unsigned integer value as an array of bytes. More...
 
static byte [] GetBytes (uint value)
 Returns the specified 32-bit unsigned integer value as an array of bytes. More...
 
static byte [] GetBytes (ulong value)
 Returns the specified 64-bit unsigned integer value as an array of bytes. More...
 
static unsafe byte [] GetBytes (float value)
 Returns the specified single-precision floating point value as an array of bytes. More...
 
static unsafe byte [] GetBytes (double value)
 Returns the specified double-precision floating point value as an array of bytes. More...
 
static char ToChar (byte[] value, int startIndex)
 Returns a Unicode character converted from two bytes at a specified position in a byte array. More...
 
static unsafe short ToInt16 (byte[] value, int startIndex)
 Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. More...
 
static unsafe int ToInt32 (byte[] value, int startIndex)
 Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. More...
 
static unsafe long ToInt64 (byte[] value, int startIndex)
 Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. More...
 
static ushort ToUInt16 (byte[] value, int startIndex)
 Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. More...
 
static uint ToUInt32 (byte[] value, int startIndex)
 Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. More...
 
static ulong ToUInt64 (byte[] value, int startIndex)
 Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. More...
 
static unsafe float ToSingle (byte[] value, int startIndex)
 Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. More...
 
static unsafe double ToDouble (byte[] value, int startIndex)
 Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. More...
 
static string ToString (byte[] value, int startIndex, int length)
 Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. More...
 
static string ToString (byte[] value)
 Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. More...
 
static string ToString (byte[] value, int startIndex)
 Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. More...
 
static bool ToBoolean (byte[] value, int startIndex)
 Returns a Boolean value converted from the byte at a specified position in a byte array. More...
 
static unsafe long DoubleToInt64Bits (double value)
 Converts the specified double-precision floating point number to a 64-bit signed integer. More...
 
static unsafe double Int64BitsToDouble (long value)
 Converts the specified 64-bit signed integer to a double-precision floating point number. More...
 

Static Public Attributes

static readonly bool IsLittleEndian = true
 Indicates the byte order ("endianness") in which data is stored in this computer architecture. More...
 

Detailed Description

Converts base data types to an array of bytes, and an array of bytes to base data types.

Definition at line 7 of file BitConverter.cs.

Member Function Documentation

◆ DoubleToInt64Bits()

static unsafe long System.BitConverter.DoubleToInt64Bits ( double  value)
static

Converts the specified double-precision floating point number to a 64-bit signed integer.

Parameters
valueThe number to convert.
Returns
A 64-bit signed integer whose value is equivalent to value .

Definition at line 563 of file BitConverter.cs.

◆ GetBytes() [1/10]

static byte [] System.BitConverter.GetBytes ( bool  value)
static

Returns the specified Boolean value as a byte array.

Parameters
valueA Boolean value.
Returns
A byte array with length 1.

Definition at line 19 of file BitConverter.cs.

◆ GetBytes() [2/10]

static byte [] System.BitConverter.GetBytes ( char  value)
static

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

Parameters
valueA character to convert.
Returns
An array of bytes with length 2.

Definition at line 31 of file BitConverter.cs.

◆ GetBytes() [3/10]

static unsafe byte [] System.BitConverter.GetBytes ( short  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 2.

Definition at line 41 of file BitConverter.cs.

◆ GetBytes() [4/10]

static unsafe byte [] System.BitConverter.GetBytes ( int  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 4.

Definition at line 57 of file BitConverter.cs.

◆ GetBytes() [5/10]

static unsafe byte [] System.BitConverter.GetBytes ( long  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 8.

Definition at line 73 of file BitConverter.cs.

◆ GetBytes() [6/10]

static byte [] System.BitConverter.GetBytes ( ushort  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 2.

Definition at line 89 of file BitConverter.cs.

◆ GetBytes() [7/10]

static byte [] System.BitConverter.GetBytes ( uint  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 4.

Definition at line 99 of file BitConverter.cs.

◆ GetBytes() [8/10]

static byte [] System.BitConverter.GetBytes ( ulong  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 8.

Definition at line 109 of file BitConverter.cs.

◆ GetBytes() [9/10]

static unsafe byte [] System.BitConverter.GetBytes ( float  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 4.

Definition at line 119 of file BitConverter.cs.

◆ GetBytes() [10/10]

static unsafe byte [] System.BitConverter.GetBytes ( double  value)
static

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

Parameters
valueThe number to convert.
Returns
An array of bytes with length 8.

Definition at line 129 of file BitConverter.cs.

◆ Int64BitsToDouble()

static unsafe double System.BitConverter.Int64BitsToDouble ( long  value)
static

Converts the specified 64-bit signed integer to a double-precision floating point number.

Parameters
valueThe number to convert.
Returns
A double-precision floating point number whose value is equivalent to value .

Definition at line 573 of file BitConverter.cs.

◆ ToBoolean()

static bool System.BitConverter.ToBoolean ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueA byte array.
startIndexThe index of the byte within value .
Returns
true if the byte at startIndex in value is nonzero; otherwise, false.
Exceptions
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 537 of file BitConverter.cs.

◆ ToChar()

static char System.BitConverter.ToChar ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array.
startIndexThe starting position within value .
Returns
A character formed by two bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex equals the length of value minus 1.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 145 of file BitConverter.cs.

◆ ToDouble()

static unsafe double System.BitConverter.ToDouble ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A double precision floating point number formed by eight bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 415 of file BitConverter.cs.

◆ ToInt16()

static unsafe short System.BitConverter.ToInt16 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A 16-bit signed integer formed by two bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex equals the length of value minus 1.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 174 of file BitConverter.cs.

◆ ToInt32()

static unsafe int System.BitConverter.ToInt32 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A 32-bit signed integer formed by four bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 214 of file BitConverter.cs.

◆ ToInt64()

static unsafe long System.BitConverter.ToInt64 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A 64-bit signed integer formed by eight bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 254 of file BitConverter.cs.

◆ ToSingle()

static unsafe float System.BitConverter.ToSingle ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A single-precision floating point number formed by four bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 385 of file BitConverter.cs.

◆ ToString() [1/3]

static string System.BitConverter.ToString ( byte []  value,
int  startIndex,
int  length 
)
static

Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
lengthThe number of array elements in value to convert.
Returns
A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value ; for example, "7F-2C-4A-00".
Exceptions
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex or length is less than zero.-or- startIndex is greater than zero and is greater than or equal to the length of value .
T:System.ArgumentExceptionThe combination of startIndex and length does not specify a position within value ; that is, the startIndex parameter is greater than the length of value minus the length parameter.

Definition at line 454 of file BitConverter.cs.

◆ ToString() [2/3]

static string System.BitConverter.ToString ( byte []  value)
static

Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.

Parameters
valueAn array of bytes.
Returns
A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value ; for example, "7F-2C-4A-00".
Exceptions
T:System.ArgumentNullExceptionvalue is null.

Definition at line 500 of file BitConverter.cs.

◆ ToString() [3/3]

static string System.BitConverter.ToString ( byte []  value,
int  startIndex 
)
static

Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value ; for example, "7F-2C-4A-00".
Exceptions
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 518 of file BitConverter.cs.

◆ ToUInt16()

static ushort System.BitConverter.ToUInt16 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueThe array of bytes.
startIndexThe starting position within value .
Returns
A 16-bit unsigned integer formed by two bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex equals the length of value minus 1.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 298 of file BitConverter.cs.

◆ ToUInt32()

static uint System.BitConverter.ToUInt32 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A 32-bit unsigned integer formed by four bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 327 of file BitConverter.cs.

◆ ToUInt64()

static ulong System.BitConverter.ToUInt64 ( byte []  value,
int  startIndex 
)
static

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

Parameters
valueAn array of bytes.
startIndexThe starting position within value .
Returns
A 64-bit unsigned integer formed by the eight bytes beginning at startIndex .
Exceptions
T:System.ArgumentExceptionstartIndex 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.
T:System.ArgumentNullExceptionvalue is null.
T:System.ArgumentOutOfRangeExceptionstartIndex is less than zero or greater than the length of value minus 1.

Definition at line 356 of file BitConverter.cs.

Member Data Documentation

◆ IsLittleEndian

readonly bool System.BitConverter.IsLittleEndian = true
static

Indicates the byte order ("endianness") in which data is stored in this computer architecture.

Returns
true if the architecture is little-endian; false if it is big-endian.

Definition at line 13 of file BitConverter.cs.


The documentation for this class was generated from the following file: