I am trying to use BitConverter to convert byte arrays to Integers so I can perform bitwise operations on the entire array. However, it appears my machine deals with bytes as little endian, but I have some static values that are in big endian.
I am able to deal with it by reversing the arrays if BitConverter.IsLittleEndian
, but I'm wondering if there is a way to force the BitConverter class to use a specific endianess instead (without creating my own class, I'm looking for an existing method).
What I'm doing now:
Dim MyBytes() as Byte = New Byte() { 0, 0, 0, 1 }
Dim MyBytesAsInteger as Integer
If BitConverter.IsLittleEndian Then
MyBytesAsInteger = BitConverter.ToInt32(MyBytes.Reverse.ToArray, 0)
Else
MyBytesAsInteger = BitConverter.ToInt32(MyBytes, 0)
End If