package com.moral.api.config.rest;
|
|
public class Crc16Utils {
|
|
public static String crc16_2017(String pushMsg, int usDataLen) {
|
int crc_reg=0xFFFF;
|
int check;
|
for(int i =0; i<usDataLen;i++){
|
crc_reg = (crc_reg>>8) ^ pushMsg.charAt(i);
|
for(int j =0; j<8; j++){
|
check = crc_reg & 0x0001;
|
crc_reg >>= 1;
|
if(check == 0x0001){
|
crc_reg ^= 0xA001;
|
}
|
}
|
}
|
return padLeft(Integer.toHexString(crc_reg).toUpperCase(), 4, "0");
|
}
|
|
public static String padLeft(String s, int w, String pc) {
|
if (pc == null) {
|
pc = "0";
|
}
|
for (int i = 0, c = w - s.length(); i < c; i++) {
|
s = pc + s;
|
}
|
return s;
|
}
|
|
|
public static String padLeftTest(String s, int w, String pc) {
|
if (pc == null) {
|
pc = "0";
|
}
|
for (int i = 0, c = w - s.length(); i < c; i++) {
|
s = pc + s;
|
}
|
return s;
|
}
|
}
|