• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calculating Checksum  RSS feed

 
Neha Pa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to calculate CRC for my application.
Logic we used for calculating CRC is
1) addition of data length,actual data,message id. (All These are stored in a byte array)
int crcSum = dataToBeSend[1] + dataToBeSend[2] + dataToBeSend[3] + dataToBeSend[4] + dataToBeSend[5];
2) Now converting this to binary format
String crcSumBin = Integer.toBinaryString(crcSum)
3) Now I am getting binary string suppose 00000001 01010011
4) What I need is only 8 bit data. so We thought of adding MSB & LSB like 01010011
+
0000001.
We will be doing this adding till we get 8 bit data. Can Anybody help me and tell me how to achieve this?
Thanks in advance.
 
Taariq San
Ranch Hand
Posts: 192
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to get the whole lot into 8 characters, try repeatedly shifting 8 bits to the right, then x-or-ing the bits, then and-ing with 0xff as a mask. Probably better to use x-or than and.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!