Java hashCode method in VB.NET The point of this method is to emulate Java hashCode().

In order for this to work the project must have arithmetic overflow allowed under:


  project --> compiler options --> advanced.  


    Public Shared Function GetHashCodeStr(value As String) As Integer
        Dim finalCode As Integer = 0

        For i As Integer = 0 To value.Length - 1
           Dim powerValue = (Convert.ToInt32(value(i)) * Math.Pow(31, value.Length - 1 - i))

        If powerValue &gt; Integer.MaxValue Then
            Dim timesGreaterThanInt = Math.Floor(powerValue / Integer.MaxValue)
            powerValue = powerValue - timesGreaterThanInt - (timesGreaterThanInt) * Integer.MaxValue
        End If

        finalCode += CInt(powerValue)
    Next

    Return finalCode
End Function
I know little about this language, but dealing with powers of 31 is surely no good idea. Most probably, it'll overflow or lose precession and you get pure garbage.

If there's something like long (64 bit integer), you can rewrite the Java implementation easily. The only relevant part is the loop doing

h = 31*h + val[off++];


Just reduce h after every iteration to the int range, so it doesn't crash your Windows overflow.

Actually, you need no long, a double (floating point with 56 bits of mantissa) would do. Simple float (24 bits mantissa) is unusable here.