Table of Contents

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

bool

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 double

The number to convert.

Returns

long

GetBytes(bool)

Returns the specified Boolean value as an array of bytes.

public static byte[] GetBytes(bool value)

Parameters

value bool

A 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 char

A 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 double

The 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 short

The 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 int

The 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 long

The 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 float

The 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 ushort

The 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 uint

The 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 ulong

The 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 long

The 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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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 int

The starting position within value.

length int

The 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

value byte[]

An array of bytes.

startIndex int

The starting position within value.

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

value byte[]

The array of bytes.

startIndex int

The starting position within value.

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

value byte[]

The array of bytes.

startIndex int

The starting position within value.

Returns

ulong

A 64-bit unsigned integer formed by two bytes beginning at startIndex.