1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 14:32:54 +01:00

Change CRC16 method

Be able to use a custom crc value for initialization.
Keeping compatibility with previous method.
This commit is contained in:
Damien Gaignon 2021-11-07 16:22:15 +01:00 committed by Gitea
parent d688f42735
commit ed47a0fcf7

View File

@ -45,8 +45,10 @@ public class CheckSums {
//thanks http://stackoverflow.com/questions/13209364/convert-c-crc16-to-java-crc16
public static int getCRC16(byte[] seq) {
int crc = 0xFFFF;
return getCRC16(seq, 0xFFFF);
}
public static int getCRC16(byte[] seq, int crc) {
for (byte b : seq) {
crc = ((crc >>> 8) | (crc << 8)) & 0xffff;
crc ^= (b & 0xff);//byte to int, trunc sign