vb System.BitConverter类(方法)实例源码

下面列出了vb System.BitConverter 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:Syste   
' Example of BitConverter class methods.
Module BitConverterDemo

    Sub Main( )

        Const formatter As String = "{0,25}{1,30}"
 
        Dim aDoubl      As Double   = 0.1111111111111111111
        Dim aSingl      As Single   = 0.1111111111111111111
        Dim aLong       As Long     = 1111111111111111111
        Dim anInt       As Integer  = 1111111111
        Dim aShort      As Short    = 11111
        Dim aChar       As Char     = "*"c
        Dim aBool       As Boolean  = True

        Console.WriteLine( _
            "This example of methods of the BitConverter class" & _
            vbCrLf & "generates the following output." & vbCrLf )
        Console.WriteLine( formatter, "argument", "Byte array" )
        Console.WriteLine( formatter, "--------", "----------" )

        ' Convert values to Byte arrays and display them.
        Console.WriteLine( formatter, aDoubl, _
            BitConverter.ToString( BitConverter.GetBytes( aDoubl ) ) )
        Console.WriteLine( formatter, aSingl, _
            BitConverter.ToString( BitConverter.GetBytes( aSingl ) ) )
        Console.WriteLine( formatter, aLong, _
            BitConverter.ToString( BitConverter.GetBytes( aLong ) ) )
        Console.WriteLine( formatter, anInt, _
            BitConverter.ToString( BitConverter.GetBytes( anInt ) ) )
        Console.WriteLine( formatter, aShort, _
            BitConverter.ToString( BitConverter.GetBytes( aShort ) ) )
        Console.WriteLine( formatter, aChar, _
            BitConverter.ToString( BitConverter.GetBytes( aChar ) ) )
        Console.WriteLine( formatter, aBool, _
            BitConverter.ToString( BitConverter.GetBytes( aBool ) ) )
    End Sub
End Module

' This example of methods of the BitConverter class

作者:VB.NET开发    项目:Syste   
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"))
      ' Convert bytes to UInt32.
      Dim uintValue As UInteger = BitConverter.ToUInt32(bytes, 0)
      Console.WriteLine("{0} = {1}: {2}", value, uintValue, 
                        If(value.Equals(uintValue), "Round-trips", "Does not round-trip"))
   End Sub
End Module

作者:VB.NET开发    项目:Syste   
Module Example
   Public Sub Main()
      Dim value As Integer = 12345678
      Dim bytes() As Byte = BitConverter.GetBytes(value)
      Console.WriteLine(BitConverter.ToString(bytes))
      
      If BitConverter.IsLittleEndian Then
         Array.Reverse(bytes) 
      End If
      Console.WriteLine(BitConverter.ToString(bytes))
      ' Call method to send byte stream across machine boundaries.
      
      ' Receive byte stream from beyond machine boundaries.
      Console.WriteLine(BitConverter.ToString(bytes))
      If BitConverter.IsLittleEndian Then     
         Array.Reverse(bytes)
      End If   
      Console.WriteLine(BitConverter.ToString(bytes))
      Dim result As Integer = BitConverter.ToInt32(bytes, 0)
      Console.WriteLine("Original value: {0}", value)
      Console.WriteLine("Returned value: {0}", result)
   End Sub
End Module
' The example displays the following output on a little-endian system:
'       4E-61-BC-00
'       00-BC-61-4E
'       00-BC-61-4E
'       4E-61-BC-00
'       Original value: 12345678
'       Returned value: 12345678


问题


面经


文章

微信
公众号

扫码关注公众号