BitConverter Class converts base data types to an array of bytes, and an array of bytes to base data types. : BitConverter « Development « VB.Net






BitConverter Class converts base data types to an array of bytes, and an array of bytes to base data types.

 

Module Example
   Public Sub Main()
      Dim value As Integer = -16
      Dim bytes() As Byte = BitConverter.GetBytes(value) 

      ' Convert bytes back to Int32.
      Dim intValue As Integer = BitConverter.ToInt32(bytes, 0)
      Console.WriteLine("{0} = {1}: {2}", 
                        value, intValue, 
                        If(value.Equals(intValue), "Round-trips", "Does not round-trip"))
   End Sub
End Module

   
  








Related examples in the same category

1.Example of the BitConverter.GetBytes( UInt32 ) method.
2.Example of the BitConverter.ToString( Byte( ) ) method.
3.Convert Byte arrays to String objects with the ToString method.
4.BitConverter.GetBytes Returns the specified 16-bit unsigned integer value as an array of bytes.
5.BitConverter.GetBytes Method Returns the specified 32-bit unsigned integer value as an array of bytes.
6.BitConverter.GetBytes(UInt64) Returns the specified 64-bit unsigned integer value as an array of bytes.
7.Convert bytes to UInt32
8.Convert values to Byte arrays and display them
9.BitConverter.DoubleToInt64Bits converts double-precision floating point number to a 64-bit signed integer.
10.BitConverter.GetBytes returns the specified Boolean value as an array of bytes.
11.BitConverter.GetBytes returns the specified Unicode character value as an array of bytes.
12.BitConverter.GetBytes returns double-precision floating point value as an array of bytes.
13.BitConverter.GetBytes (Int16) returns 16-bit signed integer value as an array of bytes.
14.BitConverter.GetBytes (Int32) returns 32-bit signed integer value as an array of bytes.
15.BitConverter.GetBytes (Int64) returns the specified 64-bit signed integer value as an array of bytes.
16.BitConverter.GetBytes (Single) returns single-precision floating point value as an array of bytes.
17.BitConverter.GetBytes (UInt16) returns 16-bit unsigned integer value as an array of bytes.
18.BitConverter.GetBytes (UInt32) returns 32-bit unsigned integer value as an array of bytes.
19.BitConverter.GetBytes (UInt64) returns 64-bit unsigned integer value as an array of bytes.
20.BitConverter.Int64BitsToDouble converts 64-bit signed integer to a double-precision floating point number.
21.BitConverter.IsLittleEndian indicates the byte order in which data is stored in this computer architecture.
22.BitConverter.ToBoolean returns a Boolean value converted from one byte at a specified position in a byte array.
23.BitConverter.ToChar returns a Unicode character converted from two bytes at a specified position in a byte array.
24.BitConverter.ToDouble returns a double converted from eight bytes at a specified position in a byte array.
25.BitConverter.ToInt16 returns a 16-bit signed integer converted from two bytes
26.BitConverter.ToInt32 returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
27.BitConverter.ToSingle returns a single-precision float number converted from four bytes
28.BitConverter.ToUInt16 returns a 16-bit unsigned integer converted from two bytes
29.BitConverter.ToUInt32 returns a 32-bit unsigned integer converted from four bytes