Class BitConverter
- Namespace
- System
- Assembly
- mscorlib.dll
Converts base data types to an array of bytes, and an array of bytes to base data types.
public static class BitConverter
- Inheritance
-
BitConverter
- Inherited Members
Properties
IsLittleEndian
Indicates the byte order ("endianess") in which data is stored in this computer architecture.
public static bool IsLittleEndian { get; }
Property Value
Methods
DoubleToInt64Bits(double)
Converts the specified double-precision floating point number to a 64-bit signed integer.
public static long DoubleToInt64Bits(double value)
Parameters
value
doubleThe number to convert.
Returns
GetBytes(bool)
Returns the specified Boolean value as an array of bytes.
public static byte[] GetBytes(bool value)
Parameters
value
boolA Boolean value.
Returns
- byte[]
An array of bytes with length 1.
GetBytes(char)
Returns the specified Unicode character value as an array of bytes.
public static byte[] GetBytes(char value)
Parameters
value
charA character to convert.
Returns
- byte[]
An array of bytes with length 2.
GetBytes(double)
Returns the specified double-precision floating point value as an array of bytes.
public static byte[] GetBytes(double value)
Parameters
value
doubleThe number to convert.
Returns
- byte[]
An array of bytes with length 8.
GetBytes(short)
Returns the specified 16-bit signed integer value as an array of bytes.
public static byte[] GetBytes(short value)
Parameters
value
shortThe number to convert.
Returns
- byte[]
An array of bytes with length 2.
GetBytes(int)
Returns the specified 32-bit signed integer value as an array of bytes.
public static byte[] GetBytes(int value)
Parameters
value
intThe number to convert.
Returns
- byte[]
An array of bytes with length 4.
GetBytes(long)
Returns the specified 64-bit signed integer value as an array of bytes.
public static byte[] GetBytes(long value)
Parameters
value
longThe number to convert.
Returns
- byte[]
An array of bytes with length 8.
GetBytes(float)
Returns the specified single-precision floating point value as an array of bytes.
public static byte[] GetBytes(float value)
Parameters
value
floatThe number to convert.
Returns
- byte[]
An array of bytes with length 4.
GetBytes(ushort)
Returns the specified 16-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(ushort value)
Parameters
value
ushortThe number to convert.
Returns
- byte[]
An array of bytes with length 2.
GetBytes(uint)
Returns the specified 32-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(uint value)
Parameters
value
uintThe number to convert.
Returns
- byte[]
An array of bytes with length 4.
GetBytes(ulong)
Returns the specified 64-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(ulong value)
Parameters
value
ulongThe number to convert.
Returns
- byte[]
An array of bytes with length 8.
Int64BitsToDouble(long)
Converts the specified 64-bit signed integer to a double-precision floating point number.
public static double Int64BitsToDouble(long value)
Parameters
value
longThe number to convert.
Returns
- double
A double-precision floating point number whose value is equivalent to value.
ToBoolean(byte[], int)
Returns a Boolean value converted from one byte at a specified position in a byte array.
public static bool ToBoolean(byte[] value, int startIndex)
Parameters
Returns
- bool
true if the byte at startIndex in value is nonzero; otherwise, false.
ToChar(byte[], int)
Returns a Unicode character converted from two bytes at a specified position in a byte array.
public static char ToChar(byte[] value, int startIndex)
Parameters
Returns
- char
A character formed by two bytes beginning at startIndex.
ToDouble(byte[], int)
Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
public static double ToDouble(byte[] value, int startIndex)
Parameters
Returns
- double
A double precision floating point number formed by eight bytes beginning at startIndex.
ToInt16(byte[], int)
Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
public static short ToInt16(byte[] value, int startIndex)
Parameters
Returns
- short
A 16-bit signed integer formed by two bytes beginning at startIndex.
ToInt32(byte[], int)
Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
public static int ToInt32(byte[] value, int startIndex)
Parameters
Returns
- int
A 32-bit signed integer formed by four bytes beginning at startIndex.
ToInt64(byte[], int)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
public static long ToInt64(byte[] value, int startIndex)
Parameters
Returns
- long
A 64-bit signed integer formed by eight bytes beginning at startIndex.
ToSingle(byte[], int)
Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
public static float ToSingle(byte[] value, int startIndex)
Parameters
Returns
- float
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.
public static string ToString(byte[] value)
Parameters
value
byte[]An array of bytes.
Returns
- 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[], int)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
public static string ToString(byte[] value, int startIndex)
Parameters
Returns
- 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[], int, int)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
public static string ToString(byte[] value, int startIndex, int length)
Parameters
value
byte[]An array of bytes.
startIndex
intThe starting position within value.
length
intThe number of array elements in value to convert.
Returns
- 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[], int)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
[CLSCompliant(false)]
public static ushort ToUInt16(byte[] value, int startIndex)
Parameters
Returns
- ushort
A 16-bit unsigned integer formed by two bytes beginning at startIndex.
ToUInt32(byte[], int)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
[CLSCompliant(false)]
public static uint ToUInt32(byte[] value, int startIndex)
Parameters
Returns
- uint
A 32-bit unsigned integer formed by two bytes beginning at startIndex.
ToUInt64(byte[], int)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
[CLSCompliant(false)]
public static ulong ToUInt64(byte[] value, int startIndex)
Parameters
Returns
- ulong
A 64-bit unsigned integer formed by two bytes beginning at startIndex.