Skip to content

Instantly share code, notes, and snippets.

@aweigold
Created October 24, 2013 20:07
Show Gist options
  • Save aweigold/7144091 to your computer and use it in GitHub Desktop.
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
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