(VB.Net)Integer转 Byte数组

1、Integer转单个字节

Public Function iByte(ByVal i As Integer) As Byte
        Dim b() As Byte = BitConverter.GetBytes(i)
        Return b(0)
End Function

2、Integer转双字节

'低字节在前,高字节在后
Public Function iByte2(ByVal i As Integer) As Byte()
        Dim btemp() As Byte = {0, 0}
        Dim b() As Byte = BitConverter.GetBytes(i)
        btemp(0) = b(1)
        btemp(1) = b(0)
        Return btemp
End Function

3、Integer转四字节

'低字节在前,高字节在后
Public Function iByte4(ByVal i As Integer) As Byte()
        Dim btemp() As Byte = {0, 0, 0, 0}
        Dim b() As Byte = BitConverter.GetBytes(i)
        btemp(0) = b(3)
        btemp(1) = b(2)
        btemp(2) = b(1)
        btemp(3) = b(0)
        Return btemp
End Function

 

你可能感兴趣的:(VB.Net)