This is a header-only library that implements SECDED encoding through constant expressions only, and was designed to enhance memory safety for low-level systems with high memory error rates.
The implementation relies on Hamming codes with an additional parity bit. The respective parity check matrices are listed in the code.
The code complies with the C89, C99, C11, C++11, C++14, and C++17 standards.
These functions can be used in C++11 and newer.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 16-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 32-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 16-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 32-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 64-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer, which is then expanded to a 32-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer, which is then expanded to a 32-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer, which is then expanded to a 64-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer, which is then expanded to a 64-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 57 bits of an unsigned integer into a 64-bit unsigned integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 57 bits of a signed integer into a 64-bit signed integer.
If the argument
v
is a constant expression, then the call to this function is a constant expression as well.For
x != y
, applying this function tox
andy
separately will result in two values that differ in at least 4 bits.
These macros can be used in C89 and newer. C++ code should use the safer C++ functions above instead.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 16-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 16-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 32-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 32-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.
Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer, which is then expanded to a 64-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer, which is then expanded to a 32-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer, which is then expanded to a 32-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer, which is then expanded to a 64-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.
Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer, which is then expanded to a 64-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer, which is then expanded to a 64-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.
Encodes the lowest 57 bits of an unsigned integer into a 64-bit unsigned integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.
Encodes the lowest 57 bits of a signed integer into a 64-bit signed integer.
Be aware that this is a macro that may evaluate
v
multiple times.For
x != y
, applying this macro tox
andy
separately will result in two values that differ in at least 4 bits.