Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   CRC/Checksum Code (http://www.go4expert.com/forums/crc-checksum-code-t11315/)

ASRRAJ 13Jun2008 15:59

CRC/Checksum Code
 
Hi All,

I m new to this group.
I m developing some message handler for that i need to verify the Messages with some checksum bit.
Can anybody help me out how to encode the messages with some checksum and vice versa.

Regards,
ASR

shabbir 13Jun2008 17:07

Re: CRC/Checksum Code
 
Moved to Programming forum

Deepkamal singh 7Aug2009 16:18

Re: CRC/Checksum Code
 
Code:

public static String getCheckSum(String value) {
        int len = value.length();
        char[] buf;
        buf = value.toCharArray();

        int result[] = new int[28];
        for (int i = 0; i < len; i += 4) {
            result[0] ^= buf[0 + i];
            result[1] ^= buf[1 + i];
            result[2] ^= buf[2 + i];
            result[3] ^= buf[3 + i];
        }

        result[0] = ~result[0];
        result[1] = ~result[1];
        result[2] = ~result[2];
        result[3] = ~result[3];

        for (int i = 7; i >= 0; i--) {
            if (i % 2 == 1) // LOW
            {
                result[i] = (result[i / 2] & 0x0F) + '0';
                if (result[i] > '9') {
                    result[i] = result[i] + 'A' - '0' - 10;
                }
            } else // HIGH
            {
                result[i] = ((result[i / 2] >> 4) & 0x0F) + '0';
                if (result[i] > '9') {
                    result[i] = result[i] + 'A' - '0' - 10;
                }
            }
        }

        return "" + (char) result[0] + (char) result[1] + (char) result[2] + (char) result[3] + (char) result[4] + (char) result[5] + (char) result[6] + (char) result[7];
    }



All times are GMT +5.5. The time now is 13:08.