See src/cerlc.erl for complete list
bit width, polynomial, initial value, final XOR value, and data reflected or not
$ rebar3 compile
$ rebar3 eunit
% Add to list of dependencies in rebar.config
{deps, [
{cerlc, "0.2.0"}
]}.
% Example: Using a predefined CRC algorithm
CrcDefn = cerlc:init(crc16_aug_ccitt),
% Data may be a binary or list of bytes
Crc = cerlc:calc_crc(Data, CrcDefn)
% Example: Creating a custom CRC algorithm
% Custom CRC parameters: {Bits, Polynomial, InitValue, FinalXorValue, Reflected}
CustomDefn = cerlc:init({8, 16#4F, 0, 16#FF, false}),
Crc = cerlc:calc_crc(Data, CustomDefn)
% Example: Using a macro to evaluate init() function at compile time
-define(CRC_DEFN, cerlc:init(crc16_aug_ccitt)).
Crc = cerlc:calc_crc(Data, ?CRC_DEFN),
# Add to list of dependencies in mix.exs
def deps do
[
{:cerlc, "~> 0.2.0"}
]
end
# Example: Using a predefined CRC algorithm
crc8_defn = :cerlc.init(:crc8)
# Data may be a binary or list of bytes
crc = :cerlc.calc_crc(data, crc8_defn)
# Example: Creating a custom CRC algorithm
# Custom CRC parameters: {bits, polynomial, init_value, final_xor_value, reflected}
custom_defn = cerlc:init({16, 0x1234, 0xFFFF, 0xFFFF, true}),
crc = :cerlc.calc_crc(data, custom_defn)
# Example: Using a module attribute to evaluate init() function at compile time
@crc32_defn :cerlc.init(:crc32_c)
crc = :cerlc.calc_crc(data, @crc32_defn)
cerlc is slower than Erlang's built in crc32() function and CRC's implemented using 'C' language NIF's.
cerlc is useful for quickly generating CRC's with little code and no other dependencies.