CRC-32: Difference between revisions

Content added Content deleted
(→‎{{header|TXR}}: Add FFI-to-Zlib version.)
Line 2,213: Line 2,213:
{{out}}
{{out}}
<pre>1095738169</pre>
<pre>1095738169</pre>
===Code===
===FFI access to Zlib===
<lang txrlisp>(with-dyn-lib "libz.so.1"
(deffi zlib-crc32 "crc32" ulong (ulong str uint)))</lang>
{{out}}
<pre>$ txr -i crc32-zlib.tl
1> (let ((s "The quick brown fox jumps over the lazy dog"))
(zlib-crc32 0 s (coded-length s)))
1095738169</pre>
Note: <code>coded-length</code> gives UTF-8 length; <code>len</code> yields a code point count. Since this is an ASCII string, the two agree.
===Lisp Code===
<lang txrlisp>(defvarl crc-tab
<lang txrlisp>(defvarl crc-tab
#(#x00000000 #x77073096 #xee0e612c #x990951ba #x076dc419 #x706af48f
#(#x00000000 #x77073096 #xee0e612c #x990951ba #x076dc419 #x706af48f