mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.5000.0 2.0.0.0 4.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.Object

The class helps manipulate value types in their fundamental form, as a series of bytes. A byte is defined as an 8-bit unsigned integer. The class includes static methods to convert each of the primitive types to and from an array of bytes, as the following table illustrates.

Type

To byte conversion

From byte conversion

-or-

-or-

If you use methods to round-trip data, make sure that the overload and the ToType method specify the same type. As the following example illustrates, restoring an array that represents a signed integer by calling the method can result in a value that is different from the original. For more information, see the entry Working with Signed Non-Decimal and Bitwise Values in the BCL Team Blog.

code reference: System.BitConverter.Class#3

The order of bytes in the array returned by the method overloads (as well as the order of bits in the integer returned by the method and the order of hexadecimal strings returned by the method) depends on whether the computer architecture is little-endian or big-endian. Similarly, the order of bytes in the array and returned by the ToIntegerValue methods and the method depends on whether the computer architecture is little-endian or big-endian. The endianness of an architecture is indicated by the property, which returns true on little-endian systems and false on big-endian systems. On little-endian systems, lower-order bytes precede higher-order bytes. On big-endian system, higher-order bytes precede lower-order bytes. The following table illustrates the difference in the byte arrays that result from passing the integer 1,234,567,890 (0x499602D2) to the method. The bytes are listed in order from the byte at index 0 to the byte at index 3.

Little-endian

D2-02-96-49

Big-endian

49-96-02-D2

Because the return value of some methods depends on system architecture, be careful when transmitting byte data beyond machine boundaries:

If all systems sending and receiving data are guaranteed to have the same endianness, nothing has be done to the data.

If systems sending and receiving data can have different endianness, always transmit data in a particular order. This means that the order of bytes in the array may have to be reversed either before sending them or after receiving them. A common convention is to transmit data in network byte order (big-endian order). The following example provides an implementation for sending an integer value in network byte order.

code reference: System.BitConverter.Class#4

If systems sending and receiving data can have different endianness and the data to be transmitted consists of signed integers, call the method to convert the data to network byte order and the method to convert it to the order required by the recipient.

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

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64 ``

  The order of bits in the integer returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  A 64-bit signed integer whose value is equivalent to .

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] `` Returns 1 byte (true: 1, false: 0)

  Returns the specified Boolean value as an array of bytes.

  An array of bytes with length 1.

  A Boolean value.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 2.

  A character to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 8.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 2.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 4.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 8.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 4.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 2.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 4.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Byte[] ``

  The order of bytes in the array returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  An array of bytes with length 8.

  The number to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Double ``

  Typically, is an integer that is returned by the method.

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

  A double-precision floating point number whose value is equivalent to .

  The number to convert.
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

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

  Different computer architectures store data using different byte orders. "Big-endian" means the most significant byte is on the left end of a word. "Little-endian" means the most significant byte is on the right end of a word.

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

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` `` To be added

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

  true if the byte at in is nonzero; otherwise, false.

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Char `` ``

  The method converts the bytes from index to + 1 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A character formed by two bytes beginning at .

  An array. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Double `` ``

  The method converts the bytes from index to + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A double precision floating point number formed by eight bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int16 `` ``

  The method converts the bytes from index to + 1 to an value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A 16-bit signed integer formed by two bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` ``

  The method converts the bytes from index to + 3 to an value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of .

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

  A 32-bit signed integer formed by four bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64 `` ``

  The method converts the bytes from index to + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A 64-bit signed integer formed by eight bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Single `` ``

  The method converts the bytes from index to + 3 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of .

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

  A single-precision floating point number formed by four bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String ``

  All the elements of are converted. The order of hexadecimal strings returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in ; for example, "7F-2C-4A-00".

  An array of bytes.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` ``

  The elements from array position to the end of the array are converted. The order of hexadecimal strings returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of ; for example, "7F-2C-4A-00".

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` `` ``

  The elements from array position are converted. If equals zero, the method returns .

  The order of hexadecimal strings returned by the method depends on whether the computer architecture is little-endian or big-endian.

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

  A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of ; for example, "7F-2C-4A-00".

  An array of bytes. The starting position within . The number of array elements in to convert.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.UInt16 `` ``

  The method converts the bytes from index to + 1 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

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

  The array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.UInt32 `` ``

  The method converts the bytes from index to + 3 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A 32-bit unsigned integer formed by four bytes beginning at .

  An array of bytes. The starting position within .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.UInt64 `` ``

  The method converts the bytes from index to + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture; for more information, see the Remarks section of the class topic.

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

  A 64-bit unsigned integer formed by the eight bytes beginning at .

  An array of bytes. The starting position within .