CRCC: AMSAT CYC2 (x^16 + x^12 + x^5 + 1) Definition ------------------------------------------------------- M L .---------------. +--<---| | | | | | | | | DATA | '---------------' | (+)--------->-----+-------------->------------+-------->--------+ | | | | | .-------. | .-------. .-----. | .---------. | +-<-| | | | |<--(+)<--| | | | |<--| | | |<--(+)<--| | | | | |<-+ '-------' '-------' '-----' '---------' <--------- M S B ---------> <--------- L S B ---------> MSByte sent first, then LSByte. (+) means "EXOR" The initial value of the CRCC register is hex FFFF Note: that calculating a crcc of a block that already includes a correct crcc as the last 2 last bytes, results in a net crcc = 0 (Because 16 "0"s are input to the crcc register!) This definition is similar to, but NOT the same as, CCITT CRC16 REM CRCC calculation in BASIC REM ------------------------- crcc%=&FFFF FOR i%=0 TO 511 ch%=buf%?i% << 8 : REM Get i'th byte; shift left 8 to align with crcc FOR j%=0 TO 7 test% = (ch% EOR crcc%) AND &8000: REM Do exor; pick out ms bit crcc% = crcc% << 1 : REM Shift crcc left 1 place ch% = ch% << 1 : REN Shift byte left 1 place IF test% <> 0 THEN crcc% = crcc% EOR &1021 NEXT NEXT Notes: << 8 is equivalent to * 256 << 1 is equivalent to * 2 & introduces a hexadecimal number % variables are integers.