In un codice che ho scaricato ho trovato questa funzione, gli si passa un array di 4 byte e deve restituire un intero a 32 bit:
Private Function GetInt32(ByVal B As Byte()) As Int32
If B.Length < 4 Then Throw New ArgumentException("Data too short (4 bytes expected)", "B")
Return B(3) << 24 Or B(2) << 16 Or B(1) << 8 Or B(0)
End Function
Questa funzione ... non funziona ... mi restituisce sempre l'intero corrispondente al primo byte, ignorando gli altri....
L'ho modificata in questo modo, forse più grezzo, ma funziona:
Private Function GetInt32(ByVal B As Byte()) As Int32
If B.Length < 4 Then Throw New ArgumentException("Data too short (4 bytes expected)", "B")
Return CInt((B(3) * (256 ^ 3)) + (B(2) * (256 ^ 2)) + (B(1) * 256) + B(0))
End Function
Adesso, pure se il problema me lo sono risolto.... Vorrei sapere come mai la funzione originale non va e come si adopera l'operatore <<