Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using java to calculate a 48 bit CRC

807580Mar 21 2010 — edited Mar 22 2010
I would like to know an easy way to calculate a 48 bit CRC given a set of bytes.
I have developed: and i believe it to be wrong
public String CheckSum48(Vector<Byte> bytes)
	{	
		long poly = 0x0111552C4310CBL; // polynomial
		long rem = 0;
		
        for (byte b : bytes) {
        	
        	rem = rem ^ (b << 40); //n-8bits
           
            // read 8 bits one at a time
            for (int i = 0; i < 8; i++) {
            	if((rem & 0x8000)==1){
            		rem = (rem << 1) ^ poly;
            	}
            	else
            	{
            		rem =  rem << 1;
            	}
            	rem = rem & 0xffffffffffffL;
            }
        }
return Long.toBinaryString(rem);
}
I'm not very confident in the method that im using ... Struggling a little with the concept. - any comments on creating a CRC and the steps involved would be appreciated.

Other problems that i feel can be factors..
1. Left bit shift in java is a signed operator.
2. Working with values over 32 bits. Unsure if working in long's is introducing an error.

Any comments on problems with creating CRC's over 32bits in java or possible comments on creating 48 bit CRC's would be appreciated.

Edited by: MichaelFluck on Mar 21, 2010 6:47 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2010
Added on Mar 21 2010
5 comments
924 views