Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!dewey.soe.berkeley.edu!oster
From: oster@dewey.soe.berkeley.edu (David Phillip Oster)
Newsgroups: comp.misc
Subject: Re: Anybody have a checksum algorithm that detects byte-swap?
Message-ID: <24875@ucbvax.BERKELEY.EDU>
Date: 28 Jun 88 07:33:14 GMT
References: <735@vsi.UUCP> <2082@pt.cs.cmu.edu> <2083@pt.cs.cmu.edu>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster)
Distribution: comp
Organization: School of Education, UC-Berkeley
Lines: 18

Just rotate the sum one bit left after each add.

	while(count--){
		sum += *src++;
		highbit = sum & 0x8000;	/* for a 16 bit sum */
		sum  <<= 1;
		if(highbit){	/* move the high bit around to the low */
			sum |= 1;
		}
	}

example:
  1, 0 gives sum=2.
  0, 1 gives sum=1.


--- David Phillip Oster            --When you asked me to live in sin with you
Arpa: oster@dewey.soe.berkeley.edu --I didn't know you meant sloth.
Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu