Created
October 24, 2013 20:07
-
-
Save aweigold/7144091 to your computer and use it in GitHub Desktop.
SQL BINARY_CHECKSUM implementation in Groovy See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=70832 for more information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long sum = 0 | |
byte overflow; | |
String text = 'mystring' | |
for (int i =0; i< text.length(); i++){ | |
sum = (long)((16* sum) ^ text.getBytes()[i]) | |
overflow = (byte) (sum / 4294967296) | |
sum = sum - overflow * 4294967296 | |
sum = sum ^ overflow | |
} | |
if (sum > 2147483647) { | |
sum = sum - 4294967296 | |
} else if (sum >= 32768 && sum <= 65535){ | |
sum = sum - 65536 | |
} else if (sum >= 128 && sum <= 255){ | |
sum = sum - 256 | |
} | |
sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment