Class BitConverter
Converts base data types to an array of bytes, and an array of bytes to base data types.
Inherited Members
Namespace: System
Assembly: mscorlib.dll
Syntax
public static class BitConverter
Properties
IsLittleEndian
Indicates the byte order ("endianess") in which data is stored in this computer architecture.
Declaration
public static bool IsLittleEndian { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
DoubleToInt64Bits(Double)
Converts the specified double-precision floating point number to a 64-bit signed integer.
Declaration
public static extern long DoubleToInt64Bits(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The number to convert. |
Returns
Type | Description |
---|---|
Int64 |
GetBytes(Boolean)
Returns the specified Boolean value as an array of bytes.
Declaration
public static extern byte[] GetBytes(bool value)
Parameters
Type | Name | Description |
---|---|---|
Boolean | value | A Boolean value. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 1. |
GetBytes(Char)
Returns the specified Unicode character value as an array of bytes.
Declaration
public static extern byte[] GetBytes(char value)
Parameters
Type | Name | Description |
---|---|---|
Char | value | A character to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 2. |
GetBytes(Double)
Returns the specified double-precision floating point value as an array of bytes.
Declaration
public static extern byte[] GetBytes(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 8. |
GetBytes(Int16)
Returns the specified 16-bit signed integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(short value)
Parameters
Type | Name | Description |
---|---|---|
Int16 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 2. |
GetBytes(Int32)
Returns the specified 32-bit signed integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 4. |
GetBytes(Int64)
Returns the specified 64-bit signed integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(long value)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 8. |
GetBytes(Single)
Returns the specified single-precision floating point value as an array of bytes.
Declaration
public static extern byte[] GetBytes(float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 4. |
GetBytes(UInt16)
Returns the specified 16-bit unsigned integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(ushort value)
Parameters
Type | Name | Description |
---|---|---|
UInt16 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 2. |
GetBytes(UInt32)
Returns the specified 32-bit unsigned integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(uint value)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 4. |
GetBytes(UInt64)
Returns the specified 64-bit unsigned integer value as an array of bytes.
Declaration
public static extern byte[] GetBytes(ulong value)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | value | The number to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with length 8. |
Int64BitsToDouble(Int64)
Converts the specified 64-bit signed integer to a double-precision floating point number.
Declaration
public static extern double Int64BitsToDouble(long value)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The number to convert. |
Returns
Type | Description |
---|---|
Double | A double-precision floating point number whose value is equivalent to value. |
ToBoolean(Byte[], Int32)
Returns a Boolean value converted from one byte at a specified position in a byte array.
Declaration
public static extern bool ToBoolean(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Boolean | true if the byte at startIndex in value is nonzero; otherwise, false. |
ToChar(Byte[], Int32)
Returns a Unicode character converted from two bytes at a specified position in a byte array.
Declaration
public static extern char ToChar(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Char | A character formed by two bytes beginning at startIndex. |
ToDouble(Byte[], Int32)
Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
Declaration
public static extern double ToDouble(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Double | A double precision floating point number formed by eight bytes beginning at startIndex. |
ToInt16(Byte[], Int32)
Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
Declaration
public static extern short ToInt16(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Int16 | A 16-bit signed integer formed by two bytes beginning at startIndex. |
ToInt32(Byte[], Int32)
Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
Declaration
public static extern int ToInt32(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer formed by four bytes beginning at startIndex. |
ToInt64(Byte[], Int32)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
Declaration
public static extern long ToInt64(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Int64 | A 64-bit signed integer formed by eight bytes beginning at startIndex. |
ToSingle(Byte[], Int32)
Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
Declaration
public static extern float ToSingle(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Single | A single-precision floating point number formed by four bytes beginning at startIndex. |
ToString(Byte[])
Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
Declaration
public static extern string ToString(byte[] value)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Returns
Type | Description |
---|---|
String | A String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A". |
ToString(Byte[], Int32)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
Declaration
public static extern string ToString(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
String | 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". |
ToString(Byte[], Int32, Int32)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
Declaration
public static extern string ToString(byte[] value, int startIndex, int length)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Int32 | length | The number of array elements in value to convert. |
Returns
Type | Description |
---|---|
String | 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". |
ToUInt16(Byte[], Int32)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
Declaration
[CLSCompliant(false)]
public static extern ushort ToUInt16(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | An array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
UInt16 | A 16-bit unsigned integer formed by two bytes beginning at startIndex. |
ToUInt32(Byte[], Int32)
Returns a 32-bit unsigned integer converted from two bytes at a specified position in a byte array.
Declaration
[CLSCompliant(false)]
public static extern uint ToUInt32(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | The array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
UInt32 | A 32-bit unsigned integer formed by two bytes beginning at startIndex. |
ToUInt64(Byte[], Int32)
Returns a 64-bit unsigned integer converted from two bytes at a specified position in a byte array.
Declaration
[CLSCompliant(false)]
public static extern ulong ToUInt64(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | The array of bytes. |
Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
UInt64 | A 64-bit unsigned integer formed by two bytes beginning at startIndex. |