Dim x As UShort = 65283 Dim y As UShort = ((x And &HFFus) << 8) + (x >> 8) '1023
Dim x As Short = -253 Dim y As Short = System.Net.IPAddress.NetworkToHostOrder(x) '1023
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim bin As Byte() = {&HFE, &HDC, &HBA, &H98, &H76, &H54, &H32, &H10} Debug.Print("データ長{0}バイト:{1}", bin.Length, BitConverter.ToString(bin)) Debug.WriteLine(" -- ToUInt16 -- ") For offset = 0 To bin.Length - 2 Dim us As UShort = BitConverter.ToUInt16(bin, offset) Dim dump As String = BitConverter.ToString(bin, offset, 2) Debug.Print("{0}バイト目からの2バイト [{1}] は 0x{2:X4} ({2:N0})", offset, dump, us) Next Debug.WriteLine(" -- ToUInt32 -- ") For offset = 0 To bin.Length - 4 Dim ui As UInteger = BitConverter.ToUInt32(bin, offset) Dim dump As String = BitConverter.ToString(bin, offset, 4) Debug.Print("{0}バイト目からの4バイト [{1}] は 0x{2:X8} ({2:N0})", offset, dump, ui) Next Debug.WriteLine(" -- ToUInt64 -- ") For offset = 0 To bin.Length - 8 Dim ul As ULong = BitConverter.ToUInt64(bin, offset) Dim dump As String = BitConverter.ToString(bin, offset, 8) Debug.Print("{0}バイト目からの8バイト [{1}] は 0x{2:X16} ({2:N0})", offset, dump, ul) Next End Sub