I'm having a problem to translate following code from C# to VB.NET.
C# code
public static byte Crc8(byte[] data, int size) {
byte checksum = 0;
for (int i=0; i<=size; i++)
checksum += data[i];
return (byte)(-checksum);
}
VB.NET code
Public Shared Function Crc8(ByVal data As Byte(), ByVal size As Integer) As Byte
Dim checksum As Byte = 0
For i As Integer = 0 To size - 1
checksum += data(i)
Next
Return CByte(-checksum)
End Function
Problem is that the VB code results in a "Arithmetic operation resulted in an overflow." error.
It seems that the "+=" operator does not operate the same way. In VB it's actually creating a sum (100 + 200 = 300) and in C# it's performing some kind of operation on the bytes (100 + 200 = 44). I can't seem to find what operation it's doing.