1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.dy.common.util;
 
@SuppressWarnings("unused")
public class CRC8_for_2_0 {
 
    @SuppressWarnings("unused")
//    public int CRC8(byte[] b, int from , int end){
//      int crc = 0;
//      for(int i = from ; i <= end ; i++){
//            crc = crc ^ (b[i]);
//            for(int j = 0; j < 8; j++) {
//              if((crc & 0x80)!=0) {
//                 crc ^= 0xe5;
//              }
//              crc *= 2;
//            }
//      }
//      return crc;
//    }
 
    public int CRC8(byte[] b, int from , int end){
        int crc = 0;
        for(int i = from ; i <= end ; i++){
            crc = crc ^ (b[i]);
            for(int j = 0; j < 8; j++) {
                if((crc & 0x80)!=0) {
                    crc *= 2;
                    crc ^= 0xe5;
                }else{
                    crc *= 2;
                }
            }
        }
        return crc;
    }
 
}