开发者

getting certain bytes from byte array in vb.net

开发者 https://www.devze.com 2022-12-15 12:10 出处:网络
I have a byte array containing bytes from a file(see my last question) now I want to get the second lot of 4 bytes from the array and conv开发者_开发技巧ert them to an integer

I have a byte array containing bytes from a file(see my last question) now I want to get the second lot of 4 bytes from the array and conv开发者_开发技巧ert them to an integer something like bytearray.get(4[start],4[length])


Dim result as Int32

result = BitConverter.ToInt32(bytearray, 4)


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

'calling it :

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

精彩评论

暂无评论...
验证码 换一张
取 消