Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calculate a CRC
Rebol [
Title: "Make CRC"
Date: 25-May-2015
Author: "Christopher Ross-Gill"
]
shift32: func [value [integer!] bits [integer!] /logical][
apply :shift [to integer! #{00000000FFFFFFFF} and to binary! value bits logical]
]
make-crc: use [legacy-table crc-table crc][
crc-table: new-line/all collect [
repeat n 256 [
crc: n - 1
loop 8 [
crc: either equal? 1 crc and 1 [
-306674912 xor shift32/logical crc -1
][
shift32/logical crc -1
]
]
keep crc
]
] false
func [chk [binary!]][
crc: -1
foreach byte chk [
byte: crc xor byte and 255 + 1
crc: crc-table/:byte xor shift32/logical crc -8
]
remove/part to binary! crc xor -1 4
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment