BitConverter : BitConverter « Development « C# / CSharp Tutorial






Convert a built-in data type into an array of bytes.

public static readonly bool IsLittleEndian

BitConverter is sealed, which means that it cannot be inherited.

Methods Defined by BitConverter

MethodMeaning
public static longDoubleToInt64Bits(double v)Converts v into a long integer.
public static byte[ ] GetBytes(bool v)Converts v into a 1-byte array.
public static byte[ ] GetBytes(char v)Converts v into a 2-byte array.
public static byte[ ] GetBytes(double v)Converts v into an 8-byte.
public static byte[ ] GetBytes(float v)Converts v into a 4-byte.
public static byte[ ] GetBytes(int v)Converts v into a 4-byte.
public static byte[ ] GetBytes(long v)Converts v into an 8-byte.
public static byte[ ] GetBytes(short v)Converts v into a 2-byte.
public static byte[ ] GetBytes(uint v)Converts v into a 4-byte.
public static byte[ ] GetBytes(ulong v)Converts v into an 8-byte.
public static byte[ ] GetBytes(ushort v)Converts v into a 2-byte.
public static doubleInt64BitsToDouble(long v)Converts v into a double floating-point value.
public static bool ToBoolean(byte[ ] a,int idx)Converts the byte at a[idx] into its bool equivalent. A non-zero value is converted to true; zero is converted to false.
public static char ToChar(byte[ ] a,int start)Converts two bytes starting at a[start] into its char equivalent.
public static double ToDouble(byte[ ] a,int start)Converts eight bytes starting at a[start] into its double equivalent.
public static short ToInt16(byte[ ] a,int start)Converts two bytes starting at a[start] into its short equivalent.
public static int ToInt32(byte[ ] a,int start)Converts four bytes starting at a[start] into its int equivalent.
public static long ToInt64(byte[ ] a,int start)Converts eight bytes starting at a[start] into its long equivalent.
public static float ToSingle(byte[ ] a,int start)Converts four bytes starting at a[start] into its float equivalent.
public static string ToString(byte[ ] a)Converts the bytes in a into a string. The string contains the hexadecimal values associated with the bytes, separated by hyphens.
public static string ToString(byte[ ] a, int start)Converts the bytes in a, beginning at a[start], into a string. The string contains the hexadecimal values associated with the bytes, separated by hyphens.
public static string ToString(byte[ ] a, int start, int count)Converts the bytes in a, beginning at a[start] and running for count bytes, into a string. The string contains the hexadecimal values associated with the bytes, separated by hyphens.
public static ushort ToUInt16(byte[ ] a,int start)Converts two bytes starting at a[start] into its ushort equivalent and returns the result.
public static uint ToUInt32(byte[ ] a,int start)Converts four bytes starting at a[start] into its uint equivalent and returns the result.
public static ulong ToUInt64(byte[ ] a,int start)Converts eight bytes starting at a[start] into its ulong equivalent and returns the result.










14.19.BitConverter
14.19.1.BitConverter
14.19.2.Convert a bool to a byte array and display
14.19.3.Convert a byte array to a bool and display
14.19.4.Convert an int to a byte array and display
14.19.5.Convert a byte array to an int and display
14.19.6.Convert different data types to byte array and convert byte array back