• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET BitConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: BitConverterDemo

' 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
开发者ID:VB.NET开发者,项目名称:System,代码行数:40,代码来源:BitConverter

输出:

argument                    Byte array
--------                    ----------
0.111111111111111       1C-C7-71-1C-C7-71-BC-3F
0.1111111                   39-8E-E3-3D
1111111111111111111       C7-71-C4-2B-AB-75-6B-0F
1111111111                   C7-35-3A-42
11111                         67-2B
*                         2A-00
True                            01


示例2: Example

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
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:BitConverter

输出:

-16 = -16: Round-trips
-16 = 4294967280: Does not round-trip


示例3: Example

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
开发者ID:VB.NET开发者,项目名称:System,代码行数:30,代码来源:BitConverter



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET DataRow类代码示例发布时间:2022-05-24
下一篇:
VB.NET Math.DivRem方法代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap