Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4787

Crc-16

$
0
0
Hello

I'm using Darrel's CRC routine to calculate a CRC but the results are not as expected.

Here is Darrel's routine -
Code:

CRC      VAR WORD
CRC_IN    VAR BYTE
Idx      VAR BYTE
CRC_Len  CON 16
CRC_Poly  CON $1021  ; x16 + x12 + x5 + 1

;-----CRC-16 -----------------------------------------------------
CRC16:
  CRC.HighByte = CRC.HighByte ^ CRC_IN
  FOR Idx = 0 to 7
    IF CRC.0(CRC_Len-1) THEN
      CRC = (CRC << 1) ^ CRC_Poly
    ELSE
      CRC = CRC << 1
    ENDIF
  NEXT Idx
RETURN

The eight bytes I'm using are "F2 AA 4C D4 60 F6 00 80"

The result I get is B2D5 rather than E23E as it should be.

Using an online calculator I get the same result, but if I tick the box "bit reflected", I get the correct result.

I'm sure I'm missing something really simple but I have tried many things without success.

Any Ideas?

Viewing all articles
Browse latest Browse all 4787

Trending Articles