mp.checksum — 14 functions
Byte inputs are 1-based byte tables.
| Function | Returns | Description |
|---|---|---|
list_crc_presets() | table | Array of {name, width, poly, init, reflect_in, reflect_out, xor_out} |
crc(preset, bytes) | table | {value, hex, width, preset} or {error} |
crc_custom(params, bytes) | table | Custom CRC; params = {name?, width, poly, init, reflect_in, reflect_out, xor_out} |
crc_region(preset, r, start?, len?) | table | CRC over a memory region (or sub-range) |
sum8(bytes) | int | 8-bit sum |
sum16(bytes) | int | 16-bit sum |
sum16_inv(bytes) | int | Inverted 16-bit sum (two's complement) |
sum_rl78(bytes) | int | Renesas RL78 / NEC 78K block checksum |
fletcher16(bytes) | int | Fletcher-16 |
fletcher32(bytes) | number | Fletcher-32 (double due to range) |
adler32(bytes) | number | Adler-32 (double) |
lrc(bytes) | int | Longitudinal redundancy check |
bcc(bytes) | int | Block check character (XOR reduction) |
list_builtins() | table | Array of {name, width} for all non-CRC builtins |
Multi-return convention for crc()
crc() returns three values: (value, hex_string, info_table).
Pick what you need — a bare assignment grabs just the value (number).
local v = mp.checksum.crc("CRC-32", data) -- 0xCBF43926 as number
local v, hex = mp.checksum.crc("CRC-32", data) -- "0xCBF43926"
local v, hex, info = mp.checksum.crc("CRC-32", data) -- info.{width, preset, error}
local v, hex = mp.checksum.crc_region("CRC-32", "Flash") -- whole region
local v, hex = mp.checksum.crc_region("CRC-32", "Flash", 0, 256) -- slice
mp.checksum.sum8(data) -- simple sum, returns int
mp.checksum.fletcher16(data)
mp.checksum.adler32(data)
mp.checksum.list_crc_presets() -- all available CRC algorithms
For Lua-based checksum scripts that drive the status bar, see Checksum scripts.