Skip to content

Instantly share code, notes, and snippets.

@rgchris
Created July 30, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgchris/d981107b44741cb63eca to your computer and use it in GitHub Desktop.
Save rgchris/d981107b44741cb63eca to your computer and use it in GitHub Desktop.
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