473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

BINARY_CHECKSUM algorithm

Hello,

Do you know if the algorithm for the BINARY_CHECKSUM function in documented
somewhere?
I would like to use it to avoid returning some string fields from the
server.
By returning only the checksum I could lookup the string in a hashtable and
I think this could make the code more efficient on slow connections.

Thanks in advanced and kind regards,

Orly Junior

Jul 23 '05 #1
3 4135
I don't know where the algorithm is documented but I don't think it will
help you. There are many more possible strings than checksums so there isn't
a one-to-one correspondence between them. Unless your set of possible
strings is constrained to a small set you couldn't guarantee to translate a
checksum back into a string and you'd still have to maintain a lookup table
of strings on the client side. So if your set of strings is small and
constrained then you may as well invent your own codes. Alternatively, take
a look at Huffman Coding or one of the zip compression algorithms.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2
Orly Junior (no****@nomail.com) writes:
Do you know if the algorithm for the BINARY_CHECKSUM function in
documented somewhere? I would like to use it to avoid returning some
string fields from the server. By returning only the checksum I could
lookup the string in a hashtable and I think this could make the code
more efficient on slow connections.


Risky business. The checksum algorithm is fairly simple-minded. I beleive
it uses some xor mechanism. I don't have the references around right now,
but I recall that SQL Server MVP Steve Kass demonstrated how some quite
small changes could result in the same checksum.

Better in such case, to augment the table with a timestamp column. Such
a column is automatically updated every time SQL Server updates the
row. So you could store the timestamp client side, and pass that value,
if the table has the same value, there is no need for a refresh.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3
Orly,

Here is what I believe it does for a single varchar
column. It's not a particularly good hash function at
all.

create function binary_checksum_varchar (
@t varchar(1000)
) returns int as begin
declare @b bigint set @b = 0
declare @c tinyint
declare @s bit set @s = 0
declare @i int set @i = 1
while @i <= len(@t) begin
set @c = ascii(substring(@t,@i,1))
set @b = @b / 16 * 16 + @b % 16 ^ @c / 16
set @b = @b * 16 + @c % 16
if @c >= 128 begin
set @b = @b ^ 0xFF
set @s = 1 - @s
end
set @b = @b % 0x0100000000 ^ @b / 0x0100000000
set @i = @i + 1
end
if @s = 1 set @b = @b ^ 0xFFFFFFFF
if @b >= 0x80000000 set @b = @b | 0xFFFFFFFF00000000
return @b
end
go
You'll find more information if some of the threads
here:

http://groups.google.co.uk/groups?q=...kass+sqlserver

Steve Kass
Drew University

Orly Junior wrote:
Hello,

Do you know if the algorithm for the BINARY_CHECKSUM function in documented
somewhere?
I would like to use it to avoid returning some string fields from the
server.
By returning only the checksum I could lookup the string in a hashtable and
I think this could make the code more efficient on slow connections.

Thanks in advanced and kind regards,

Orly Junior

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
5
by: Liam Caffrey | last post by:
Hi, It appears that binary_checksum can give the same checksum for different strings, which is a bit worrying. (I guess the algorithm is the problem in the context of a repeating pattern.) ...
2
by: Orly Junior | last post by:
Gentlemen, I am using the following query to get a list of grouped checksum data. SELECT CAST(Field0_datetime AS INT), CHECKSUM_AGG(BINARY_CHECKSUM(Field1_bigint, Field2_datetime,...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
0
by: aruna | last post by:
hey guys i earlier had very valuable responses from you all for base64 encoding algorithm.so thank for that. so now i need your assistance to do a float encoding algorithm. you may wonder why i'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.