19.02.2019, 02:52
(
Последний раз редактировалось [eLg]elite; 19.02.2019 в 03:28.
)
Consider this code (I found somewhere years ago):
Now this is my Java implementation:
Quora says it's impossible to use a bitwise operator on a double or floating-point variable; Pawn does it with ease. It works as long as I use Math.round to make the result an integer, but that doesn't work properly for hashing. Why is this?
EDIT: I don't know why I didn't realize that since Pawn uses dynamic types it converts the floating-point to a string (array of chars) and THEN shifts. My issue is solved.
Код:
stock udb_hash(buf[]) { new length=strlen(buf); new s1 = 1; new s2 = 0; new n; for (n=0; n<length; n++) { s1 = (s1 + buf[n]) % 65521; s2 = (s2 + s1) % 65521; } return (s2 << 16) + s1; }
Код:
private double udb_hash(String pass) { int length = pass.length(); int s1 = 1; double s2 = 0; double s3 = 0; for (int n = 0; n < length; n++) { s1 = (s1 + (int) pass.charAt(n)) % 65521; s2 = (s2 + s1) % 65521; } s3 = (Math.round(s2 << 16) + s1; return s3; }
EDIT: I don't know why I didn't realize that since Pawn uses dynamic types it converts the floating-point to a string (array of chars) and THEN shifts. My issue is solved.