public static int crc_16_rec(byte[] buffer) {
    //--------------------------------------------------------------------
     int  i;
    short ucBit, ucCarry;
    //--------------------------------------------------------------------
     int usPoly = (int)0x8408 ;//reversed 0x1021
     int usCRC  = 0;
    //--------------------------------------------------------------------
     int lenght =  buffer.length;
    for (i = 0; i < lenght; i++) {
        
        usCRC ^= (buffer[i]& 0xff);
        for (ucBit = 0; ucBit < 8; ucBit++) {
            ucCarry = (short)(usCRC & 1);
            usCRC >>= 1;
            if (ucCarry == 1) {
                usCRC ^= usPoly;
            }
        }
    }
    //--------------------------------------------------------------------
    return usCRC;
    //--------------------------------------------------------------------
}