package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; // This code and this particular library are from the NightScout android uploader // Check them out here: https://github.com/nightscout/android-uploader // Some of this code may have been modified for use in this project public class CRC16 { public static byte[] calculate(byte[] buff, int start, int end) { int crcShort = 0; for (int i = start; i < end; i++) { crcShort = ((crcShort >>> 8) | (crcShort << 8) )& 0xffff; crcShort ^= (buff[i] & 0xff); crcShort ^= ((crcShort & 0xff) >> 4); crcShort ^= (crcShort << 12) & 0xffff; crcShort ^= ((crcShort & 0xFF) << 5) & 0xffff; } crcShort &= 0xffff; return new byte[] {(byte) (crcShort & 0xff), (byte) ((crcShort >> 8) & 0xff)}; } }