当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET BitConverter.GetBytes方法代码示例

本文整理汇总了VB.NET中System.BitConverter.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BitConverter.GetBytes方法的具体用法?VB.NET BitConverter.GetBytes怎么用?VB.NET BitConverter.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.BitConverter的用法示例。


在下文中一共展示了BitConverter.GetBytes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Module Example
   Public Sub Main()
      ' Define Boolean true and false values.
      Dim values() As Boolean = { true, false }

      ' Display the value and its corresponding byte array.
      Console.WriteLine("{0,10}{1,16}", "Boolean", "Bytes")
      Console.WriteLine()
      
      For Each value In values
         Dim bytes() As Byte = BitConverter.GetBytes(value) 
         Console.WriteLine("{0,10}{1,16}", value, 
                           BitConverter.ToString(bytes))
      Next
    End Sub 
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:BitConverter.GetBytes

输出:

Boolean           Bytes

True              01
False              00

示例2: GetBytesCharDemo

' Example of the BitConverter.GetBytes( Char ) method.
Module GetBytesCharDemo

    Const formatter As String = "{0,10}{1,16}"
 
    ' Convert a Char argument to a Byte array and display it.
    Sub GetBytesChar( argument As Char )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( Char ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Char", "Byte array" )
        Console.WriteLine( formatter, "----", "----------" )
          
        ' Convert Char values and display the results.
        GetBytesChar( Chr( 0 ) )
        GetBytesChar( " "c )
        GetBytesChar( "*"c )
        GetBytesChar( "3"c )
        GetBytesChar( "A"c )
        GetBytesChar( "["c )
        GetBytesChar( "a"c )
        GetBytesChar( "{"c )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( Char )
开发者ID:VB.NET开发者,项目名称:System,代码行数:35,代码来源:BitConverter.GetBytes

输出:

Char      Byte array
----      ----------
00-00
20-00
*           2A-00
3           33-00
A           41-00
[           5B-00
a           61-00
{           7B-00

示例3: GetBytesDoubleDemo

' Example of the BitConverter.GetBytes( Double ) method.
Module GetBytesDoubleDemo

    Const formatter As String = "{0,25:E16}{1,30}"
 
    ' Convert a Double argument to a Byte array and display it.
    Sub GetBytesDouble( argument As Double )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( Double ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Double", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )
          
        ' Convert Double values and display the results.
        GetBytesDouble( 0.0 )
        GetBytesDouble( 1.0 )
        GetBytesDouble( 255.0 )
        GetBytesDouble( 4294967295.0 )
        GetBytesDouble( 0.00390625 )
        GetBytesDouble( 0.00000000023283064365386962890625 )
        GetBytesDouble( 1.23456789012345E-300 )
        GetBytesDouble( 1.2345678901234565 )
        GetBytesDouble( 1.2345678901234567 )
        GetBytesDouble( 1.2345678901234569 )
        GetBytesDouble( 1.23456789012345678E+300 )
        GetBytesDouble( Double.MinValue )
        GetBytesDouble( Double.MaxValue )
        GetBytesDouble( Double.Epsilon )
        GetBytesDouble( Double.NaN )
        GetBytesDouble( Double.NegativeInfinity )
        GetBytesDouble( Double.PositiveInfinity )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( Double )
开发者ID:VB.NET开发者,项目名称:System,代码行数:44,代码来源:BitConverter.GetBytes

输出:

Double                    Byte array
------                    ----------
0.0000000000000000E+000       00-00-00-00-00-00-00-00
1.0000000000000000E+000       00-00-00-00-00-00-F0-3F
2.5500000000000000E+002       00-00-00-00-00-E0-6F-40
4.2949672950000000E+009       00-00-E0-FF-FF-FF-EF-41
3.9062500000000000E-003       00-00-00-00-00-00-70-3F
2.3283064365386963E-010       00-00-00-00-00-00-F0-3D
1.2345678901234500E-300       DF-88-1E-1C-FE-74-AA-01
1.2345678901234565E+000       FA-59-8C-42-CA-C0-F3-3F
1.2345678901234567E+000       FB-59-8C-42-CA-C0-F3-3F
1.2345678901234569E+000       FC-59-8C-42-CA-C0-F3-3F
1.2345678901234569E+300       52-D3-BB-BC-E8-7E-3D-7E
-1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-FF
1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-7F
4.9406564584124654E-324       01-00-00-00-00-00-00-00
NaN       00-00-00-00-00-00-F8-FF
-Infinity       00-00-00-00-00-00-F0-FF
Infinity       00-00-00-00-00-00-F0-7F

示例4: Example

Module Example
    Public Sub Main( )
        ' Define an array of integers.
        Dim values() As Integer  = { 0, 15, -15, 10000,  -10000, 
                                     Short.MinValue, Short.MaxValue }
          
        ' Convert each integer to a byte array.
        Console.WriteLine("{0,16}{1,10}{2,17}", "Integer", 
                          "Endian", "Byte Array")
        Console.WriteLine("{0,16}{1,10}{2,17}", "---", "------", 
                          "----------" )
        For Each value In values
          Dim byteArray() As Byte = BitConverter.GetBytes(value)
          Console.WriteLine("{0,16}{1,10}{2,17}", value, 
                            If(BitConverter.IsLittleEndian, "Little", " Big"), 
                            BitConverter.ToString(byteArray))
        Next
    End Sub
End Module
' This example displays output like the following:
'              Integer    Endian       Byte Array
'                  ---    ------       ----------
'                    0    Little            00-00
'                   15    Little            0F-00
'                  -15    Little            F1-FF
'                10000    Little            10-27
'               -10000    Little            F0-D8
'               -32768    Little            00-80
'                32767    Little            FF-7F
开发者ID:VB.NET开发者,项目名称:System,代码行数:29,代码来源:BitConverter.GetBytes

示例5: Example

Module Example
    Public Sub Main( )
        ' Define an array of integers.
        Dim values() As Integer  = { 0, 15, -15, &h100000,  -&h100000, 1000000000,
                                     -1000000000, Int32.MinValue, Int32.MaxValue }
          
        ' Convert each integer to a byte array.
        Console.WriteLine("{0,16}{1,10}{2,17}", "Integer", 
                          "Endian", "Byte Array")
        Console.WriteLine("{0,16}{1,10}{2,17}", "---", "------", 
                          "----------" )
        For Each value In values
          Dim byteArray() As Byte = BitConverter.GetBytes(value)
          Console.WriteLine("{0,16}{1,10}{2,17}", value, 
                            If(BitConverter.IsLittleEndian, "Little", " Big"), 
                            BitConverter.ToString(byteArray))
        Next
    End Sub
End Module
' This example displays output like the following:
'              Integer    Endian       Byte Array
'                  ---    ------       ----------
'                    0    Little      00-00-00-00
'                   15    Little      0F-00-00-00
'                  -15    Little      F1-FF-FF-FF
'              1048576    Little      00-00-10-00
'             -1048576    Little      00-00-F0-FF
'           1000000000    Little      00-CA-9A-3B
'          -1000000000    Little      00-36-65-C4
'          -2147483648    Little      00-00-00-80
'           2147483647    Little      FF-FF-FF-7F
开发者ID:VB.NET开发者,项目名称:System,代码行数:31,代码来源:BitConverter.GetBytes

示例6: Example

Public Module Example
    Public Sub Main()
        ' Define an array of Int64 values.
        Dim values() As Long = { 0, &hFFFFFF, -&hFFFFFF, 1000000000, -1000000000,
                                 &h100000000, -&h100000000, &hAAAAAAAAAAAA, 
                                 -&hAAAAAAAAAAAA, 1000000000000000000, 
                                 -1000000000000000000, Long.MinValue, 
                                 Long.MaxValue }
        
        Console.WriteLine( "{0,22}{1,10}{2,30}", "Int64", "Endian", "Byte Array" )
        Console.WriteLine( "{0,22}{1,10}{2,30}", "----", "------", "----------" )
        
        For Each value in values
            ' Convert each Int64 value to a byte array.
            Dim byteArray() As Byte = BitConverter.GetBytes(value)
            ' Display the result.
            Console.WriteLine("{0,22}{1,10}{2,30}", value, 
                              If(BitConverter.IsLittleEndian, "Little", "Big"),
                              BitConverter.ToString(byteArray))
        
        Next  
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:23,代码来源:BitConverter.GetBytes

输出:

Int64    Endian                    Byte Array
----    ------                    ----------
0    Little       00-00-00-00-00-00-00-00
16777215    Little       FF-FF-FF-00-00-00-00-00
-16777215    Little       01-00-00-FF-FF-FF-FF-FF
1000000000    Little       00-CA-9A-3B-00-00-00-00
-1000000000    Little       00-36-65-C4-FF-FF-FF-FF
4294967296    Little       00-00-00-00-01-00-00-00
-4294967296    Little       00-00-00-00-FF-FF-FF-FF
187649984473770    Little       AA-AA-AA-AA-AA-AA-00-00
-187649984473770    Little       56-55-55-55-55-55-FF-FF
1000000000000000000    Little       00-00-64-A7-B3-B6-E0-0D
-1000000000000000000    Little       00-00-9C-58-4C-49-1F-F2
-9223372036854775808    Little       00-00-00-00-00-00-00-80
9223372036854775807    Little       FF-FF-FF-FF-FF-FF-FF-7F

示例7: GetBytesSingleDemo

' Example of the BitConverter.GetBytes( Single ) method.
Module GetBytesSingleDemo

    Const formatter As String = "{0,16:E7}{1,20}"
 
    ' Convert a Single argument to a Byte array and display it.
    Sub GetBytesSingle( argument As Single )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( Single ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Single", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )
          
        ' Convert Single values and display the results.
        GetBytesSingle( 0.0F )
        GetBytesSingle( 1.0F )
        GetBytesSingle( 15.0F )
        GetBytesSingle( 65535.0F )
        GetBytesSingle( 0.00390625F )
        GetBytesSingle( 0.00000000023283064365386962890625F )
        GetBytesSingle( 1.2345E-35F )
        GetBytesSingle( 1.2345671F )
        GetBytesSingle( 1.2345673F )
        GetBytesSingle( 1.2345677F )
        GetBytesSingle( 1.23456789E+35F )
        GetBytesSingle( Single.MinValue )
        GetBytesSingle( Single.MaxValue )
        GetBytesSingle( Single.Epsilon )
        GetBytesSingle( Single.NaN )
        GetBytesSingle( Single.NegativeInfinity )
        GetBytesSingle( Single.PositiveInfinity )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( Single )
开发者ID:VB.NET开发者,项目名称:System,代码行数:44,代码来源:BitConverter.GetBytes

输出:

Single          Byte array
------          ----------
0.0000000E+000         00-00-00-00
1.0000000E+000         00-00-80-3F
1.5000000E+001         00-00-70-41
6.5535000E+004         00-FF-7F-47
3.9062500E-003         00-00-80-3B
2.3283064E-010         00-00-80-2F
1.2345000E-035         49-46-83-05
1.2345671E+000         4B-06-9E-3F
1.2345673E+000         4D-06-9E-3F
1.2345676E+000         50-06-9E-3F
1.2345679E+035         1E-37-BE-79
-3.4028235E+038         FF-FF-7F-FF
3.4028235E+038         FF-FF-7F-7F
1.4012985E-045         01-00-00-00
NaN         00-00-C0-FF
-Infinity         00-00-80-FF
Infinity         00-00-80-7F

示例8: GetBytesUInt16Demo

' Example of the BitConverter.GetBytes( UInt16 ) method.
Module GetBytesUInt16Demo

    Const formatter As String = "{0,10}{1,13}"
 
    ' Convert a UInt16 argument to a Byte array and display it.
    Sub GetBytesUInt16( argument As UInt16 )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( UInt16 ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "UInt16", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )
          
        ' Convert UInt16 values and display the results.
        GetBytesUInt16( Convert.ToUInt16( 15 ) )
        GetBytesUInt16( Convert.ToUInt16( 1023 ) )
        GetBytesUInt16( Convert.ToUInt16( 10000 ) )
        GetBytesUInt16( Convert.ToUInt16( 0 ) )
        GetBytesUInt16( Convert.ToUInt16( Int16.MaxValue ) )
        GetBytesUInt16( Convert.ToUInt16( 65535 ) )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( UInt16 )
开发者ID:VB.NET开发者,项目名称:System,代码行数:33,代码来源:BitConverter.GetBytes

输出:

UInt16   Byte array
------   ----------
15        0F-00
1023        FF-03
10000        10-27
0        00-00
32767        FF-7F
65535        FF-FF

示例9: GetBytesUInt32Demo

' Example of the BitConverter.GetBytes( UInt32 ) method.
Module GetBytesUInt32Demo

    Const formatter As String = "{0,16}{1,20}"
 
    ' Convert a UInt32 argument to a Byte array and display it.
    Sub GetBytesUInt32( argument As UInt32 )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( UInt32 ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "UInt32", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )
          
        ' Convert UInt32 values and display the results.
        GetBytesUInt32( Convert.ToUInt32( 15 ) )
        GetBytesUInt32( Convert.ToUInt32( 1023 ) )
        GetBytesUInt32( Convert.ToUInt32( &H100000 ) )
        GetBytesUInt32( Convert.ToUInt32( 1000000000 ) )
        GetBytesUInt32( Convert.ToUInt32( 0 ) )
        GetBytesUInt32( Convert.ToUInt32( Int32.MaxValue ) )
        GetBytesUInt32( Convert.ToUInt32( 4294967295 ) )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( UInt32 )
开发者ID:VB.NET开发者,项目名称:System,代码行数:34,代码来源:BitConverter.GetBytes

输出:

UInt32          Byte array
------          ----------
15         0F-00-00-00
1023         FF-03-00-00
1048576         00-00-10-00
1000000000         00-CA-9A-3B
0         00-00-00-00
2147483647         FF-FF-FF-7F
4294967295         FF-FF-FF-FF

示例10: GetBytesUInt64Demo

' Example of the BitConverter.GetBytes( UInt64 ) method.
Imports System.Globalization

Module GetBytesUInt64Demo

    Const formatter As String = "{0,22}{1,30}"
 
    ' Convert a UInt64 argument to a Byte array and display it.
    Sub GetBytesUInt64( argument As UInt64 )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( UInt64 ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "UInt64", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )
          
        ' Convert UInt64 values and display the results.
        GetBytesUInt64( Convert.ToUInt64( &HFFFFFF ) )
        GetBytesUInt64( Convert.ToUInt64( 1000000000 ) )
        GetBytesUInt64( Convert.ToUInt64( &H100000000 ) )
        GetBytesUInt64( Convert.ToUInt64( &HAAAAAAAAAAAA ) )
        GetBytesUInt64( Convert.ToUInt64( 1000000000000000000 ) )
        GetBytesUInt64( UInt64.Parse( "10000000000000000000" ) )
        GetBytesUInt64( Convert.ToUInt64( 0 ) )
        GetBytesUInt64( Convert.ToUInt64( Int64.MaxValue ) )
        GetBytesUInt64( UInt64.Parse( "18446744073709551615" ) )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( UInt64 )
开发者ID:VB.NET开发者,项目名称:System,代码行数:38,代码来源:BitConverter.GetBytes

输出:

UInt64                    Byte array
------                    ----------
16777215       FF-FF-FF-00-00-00-00-00
1000000000       00-CA-9A-3B-00-00-00-00
4294967296       00-00-00-00-01-00-00-00
187649984473770       AA-AA-AA-AA-AA-AA-00-00
1000000000000000000       00-00-64-A7-B3-B6-E0-0D
10000000000000000000       00-00-E8-89-04-23-C7-8A
0       00-00-00-00-00-00-00-00
9223372036854775807       FF-FF-FF-FF-FF-FF-FF-7F
18446744073709551615       FF-FF-FF-FF-FF-FF-FF-FF


注:本文中的System.BitConverter.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。