forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytesint16.vb
31 lines (30 loc) · 1.32 KB
/
bytesint16.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
' <Snippet3>
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
' </Snippet3>