' Convert 2 bytes (little endian) to a signed int.
' b(0) = LSB, b(1) = MSB.
' Example <code>
' Log(BytesToInt(Array As Byte(0x78, 0x00)))
' Result = 120
' Log(BytesToInt(Array As Byte(0x88, 0xFF)))
' Result = -120
' </code>
Public Sub BytesToInt(b() As Byte) As Int
If b.Length < 2 Then Return 0
Dim value As Int = Bit.Or(Bit.And(b(0), 0xFF), Bit.ShiftLeft(Bit.And(b(1), 0xFF), 8))
If value > 32767 Then value = value - 65536 ' sign extend
Return value
End Sub