本文整理汇总了VB.NET中System.BitConverter.ToInt32方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BitConverter.ToInt32方法的具体用法?VB.NET BitConverter.ToInt32怎么用?VB.NET BitConverter.ToInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.BitConverter
的用法示例。
在下文中一共展示了BitConverter.ToInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
' Create an Integer from a 4-byte array.
Dim bytes1() As Byte = { &hEC, &h00, &h00, &h00 }
Console.WriteLine("{0}--> 0x{1:X4} ({1:N0})", FormatBytes(bytes1),
BitConverter.ToInt32(bytes1, 0))
' Create an Integer from the upper four bytes of a byte array.
Dim bytes2() As Byte = BitConverter.GetBytes(Int64.MaxValue \ 2)
Console.WriteLine("{0}--> 0x{1:X4} ({1:N0})", FormatBytes(bytes2),
BitConverter.ToInt32(bytes2, 4))
' Round-trip an integer value.
Dim original As Integer = CInt(16^3)
Dim bytes3() As Byte = BitConverter.GetBytes(original)
Dim restored As Integer = BitConverter.ToInt32(bytes3, 0)
Console.WriteLine("0x{0:X4} ({0:N0}) --> {1} --> 0x{2:X4} ({2:N0})", original,
FormatBytes(bytes3), restored)
End Sub
Private Function FormatBytes(bytes() As Byte) As String
Dim value As String = ""
For Each byt In bytes
value += String.Format("{0:X2} ", byt)
Next
Return value
End Function
End Module
输出:
EC 00 00 00 --> 0x00EC (236) FF FF FF FF FF FF FF 3F --> 0x3FFFFFFF (1,073,741,823) 0x1000 (4,096) --> 00 10 00 00 --> 0x1000 (4,096)