crc16(n)
πΈ crc16(n) β the manual page, but make it make sense πΈ
okay so bestie, this is crc16(n) from the Cyclic Redundancy Checks corner of the manual. It's long, so we're doing it in parts β this is part 1, and I'm not skimping on a single flag, periodt. π
β¨ NAME β¨
crc16 β Perform a 16bit Cyclic Redundancy Check
π¦ SYNOPSIS π¦
package require Tcl 8.5 9
package require crc16 ?1.1.5?
::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::umts ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::umts ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::cms ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::cms ?-format format? ?-seed value? ?-implementation procname? -filename file
π DESCRIPTION π
So this package is a Tcl-only implementation of the CRC algorithms, built on the info from http://www.microconsultants.com/tips/crc/crc.txt β credit where it's due, iykyk.
There are a lot of permutations for calculating CRC checksums, and this package handles all of them. The defaults are already set up for the most common cases, so you don't have to think about it unless you want to. π«Ά
π COMMANDS π
::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::umts ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::umts ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -filename file
::crc::cms ?-format format? ?-seed value? ?-implementation procname? -- message
::crc::cms ?-format format? ?-seed value? ?-implementation procname? -filename file
So like, the way this works: the command takes either string data or a file name, and it hands you back a checksum value computed with the CRC algorithm. π«
The command you pick is what sets up the CRC polynomial, the initial value and the bit ordering for whichever standard checksum you're trying to calculate. And the result gets formatted using the format(n) specifier you gave it β or, if you gave none, as an unsigned integer (%u) by default.
There are a bunch of common polynomials in use with CRC, and the most commonly used ones are already in this package. And because the devs love us, each one has a command alias in the crc namespace. convenient? iconic. π
Also, real talk: you can implement the CRC-32 checksum using this crc16 package, because the implementation is generic enough to stretch to 32 bit checksums. That's literally already been done as an example. But β and this is the important part β it is not the fastest way to do this algorithm in Tcl, and there's a separate crc32 package available if speed is your thing. no cap.
π OPTIONS π
-filename nameβ give me a checksum for the file contents instead of for the parameter data. file girlies rise π-format stringβ hand back the checksum using an alternative format template.-seed valueβ pick an alternative seed value for the CRC calculation. The default is0for the CRC16 calculation and0xFFFFfor the CCITT version. This is lowkey so useful for calculating the CRC of data structures without first converting the whole entire structure into a string β you can take the CRC of the previous member and use it as the seed for the next member's CRC. It's also what you use for accumulating a checksum out of fragments of a big message (or file). π§-implementation procnameβ this hook exists so you can bring your own implementation (maybe a C compiled extension, main character energy). The procedure you specify gets called with two parameters: the first is the data to be checksummed, the second is the seed value. An integer is expected back as the result. The package already ships some implementations of standard CRC polynomials forXMODEM,CCITTand the usual CRC-16 checksum. And for convenience, extra commands have been provided that use these implementations. π«Ά--β terminate option processing.
β οΈ okay this one matters SO much: using the option termination flag is important when you're processing data from parameters. If the binary data happens to look like one of the options above, then that data will be read as an option if this marker isn't there. Always use the -- option termination flag before giving the data argument. always. π
π EXAMPLES π
% crc::crc16 -- "Hello, World!"
64077
% crc::crc-ccitt -- "Hello, World!"
26586
% crc::crc16 -format 0x%X -- "Hello, World!"
0xFA4D
% crc::crc16 -file crc16.tcl
51675
π AUTHORS π
Pat Thoyts
okay bestie that's part 1, there's more coming so don't go anywhere π
π BUGS, IDEAS, FEEDBACK π
okay bestie, real talk: this doc and the whole package it describes? undoubtedly gonna have bugs and other problems. that's just how software is, no cap. not a vibe, but it's the truth. π
so if you find something busted, pls report it in the category crc of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
and hey β got ideas for enhancements for the package and/or the documentation? report those too!! we wanna hear them, fr fr. your glow-up suggestions are welcome. β¨
when you're proposing code changes, pls hand over unified diffs, i.e. the output of diff -u. that's the format, periodt.
π‘ also!! attachments are strongly preferred over inlined patches. like, hugely. to attach one, go to the Edit form of the ticket immediately after its creation, then use the left-most button in the secondary navigation bar. that's the whole trick, iykyk. π
π SEE ALSO π
go check these out too, they're the whole friend group:
π KEYWORDS π¦
so if you're searching for this page later, these are the lil tags that'll find it:
checksum, cksum, crc, crc16, crc32, cyclic redundancy check, data integrity, security
π CATEGORY π
it lives under: Hashes, checksums, and encryption
iconic little neighborhood tbh. π
Β©οΈ COPYRIGHT π
Copyright (c) 2002, 2017, Pat Thoyts
and that's a wrap on the whole page bestie!! π«Ά this lil masterpiece is from tcllib, version 1.1.5, filed under crc16(n) β and the date stamp at the bottom of the page is part of the footer too, right there next to the version. go checksum something and slay. πβ¨ππ¦πΈπ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2002, 2017, Pat Thoyts
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms