从vb.net中的字节数组中获取某些字节

时间:2010-01-02 13:44:52

标签: .net vb.net arrays byte

我有一个包含文件中字节的字节数组(see my last question) 现在我想从数组中获取第二批4个字节并将它们转换为整数 像bytearray.get(4[start],4[length])

这样的东西

2 个答案:

答案 0 :(得分:3)

Dim result as Int32

result = BitConverter.ToInt32(bytearray, 4)

答案 1 :(得分:1)

Public Function ByteArrayToInteger(ByRef ByteArray() As Byte, ByRef StartIndex As Integer, ByRef EndIndex As Integer) As Integer
    Dim bSubArray(0 To EndIndex - StartIndex) As Byte
    For i As Integer = StartIndex To EndIndex
        bSubArray(i - StartIndex) = ByteArray(i)
    Next
    Return BitConverter.ToInt32(bSubArray, 0)
End Function

'呼唤它:

Dim b() As Byte = {1, 2, 3, 4, 5, 6}
Dim x As Integer = ByteArrayToInteger(b, 0, 3)