{"id":15400398,"url":"https://github.com/tniessen/constexpr-secded","last_synced_at":"2025-06-15T11:34:45.885Z","repository":{"id":152090577,"uuid":"300477231","full_name":"tniessen/constexpr-secded","owner":"tniessen","description":"Header-only implementation of SECDED encoding as C/C++ constant expressions","archived":false,"fork":false,"pushed_at":"2024-02-01T18:32:07.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T05:44:08.695Z","etag":null,"topics":["coding-theory","constexpr","memory-safety"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tniessen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-02T02:09:45.000Z","updated_at":"2024-12-28T14:21:41.000Z","dependencies_parsed_at":"2024-10-20T11:17:11.889Z","dependency_job_id":null,"html_url":"https://github.com/tniessen/constexpr-secded","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"e1eaa09d6cd0758a2c9e93619592d9213a4516b1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tniessen%2Fconstexpr-secded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tniessen%2Fconstexpr-secded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tniessen%2Fconstexpr-secded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tniessen%2Fconstexpr-secded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tniessen","download_url":"https://codeload.github.com/tniessen/constexpr-secded/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244547604,"owners_count":20470103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coding-theory","constexpr","memory-safety"],"created_at":"2024-10-01T15:53:49.395Z","updated_at":"2025-03-20T04:08:07.850Z","avatar_url":"https://github.com/tniessen.png","language":"C++","readme":"# constexpr-secded\n\nThis is a header-only library that implements SECDED encoding through constant\nexpressions only, and was designed to enhance memory safety for low-level\nsystems with high memory error rates.\n\nThe implementation relies on Hamming codes with an additional parity bit. The\nrespective parity check matrices are listed in\n[the code](include/constexpr-secded.h).\n\nThe code complies with the C89, C99, C11, C++11, C++14, and C++17 standards.\n\n## C++ functions\n\nThese functions can be used in C++11 and newer.\n\n\u003c!---cpp start---\u003e\n\n#### `constexpr std::uint8_t secded_encode_4_bits\u003cstd::uint8_t\u003e(std::uint8_t v)`\n\n\u003e Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::uint16_t secded_encode_4_bits\u003cstd::uint16_t\u003e(std::uint8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::uint32_t secded_encode_4_bits\u003cstd::uint32_t\u003e(std::uint8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `constexpr std::uint64_t secded_encode_4_bits\u003cstd::uint64_t\u003e(std::uint8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.\n\n#### `constexpr std::int8_t secded_encode_4_bits\u003cstd::int8_t\u003e(std::int8_t v)`\n\n\u003e Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::int16_t secded_encode_4_bits\u003cstd::int16_t\u003e(std::int8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::int32_t secded_encode_4_bits\u003cstd::int32_t\u003e(std::int8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `constexpr std::int64_t secded_encode_4_bits\u003cstd::int64_t\u003e(std::int8_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.\n\n#### `constexpr std::uint16_t secded_encode_11_bits\u003cstd::uint16_t\u003e(std::uint16_t v)`\n\n\u003e Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::uint32_t secded_encode_11_bits\u003cstd::uint32_t\u003e(std::uint16_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::uint64_t secded_encode_11_bits\u003cstd::uint64_t\u003e(std::uint16_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `constexpr std::int16_t secded_encode_11_bits\u003cstd::int16_t\u003e(std::int16_t v)`\n\n\u003e Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::int32_t secded_encode_11_bits\u003cstd::int32_t\u003e(std::int16_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::int64_t secded_encode_11_bits\u003cstd::int64_t\u003e(std::int16_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `constexpr std::uint32_t secded_encode_26_bits\u003cstd::uint32_t\u003e(std::uint32_t v)`\n\n\u003e Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::uint64_t secded_encode_26_bits\u003cstd::uint64_t\u003e(std::uint32_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::int32_t secded_encode_26_bits\u003cstd::int32_t\u003e(std::int32_t v)`\n\n\u003e Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::int64_t secded_encode_26_bits\u003cstd::int64_t\u003e(std::int32_t v)`\n\n\u003e 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.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `constexpr std::uint64_t secded_encode_57_bits\u003cstd::uint64_t\u003e(std::uint64_t v)`\n\n\u003e Encodes the lowest 57 bits of an unsigned integer into a 64-bit unsigned integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `constexpr std::int64_t secded_encode_57_bits\u003cstd::int64_t\u003e(std::int64_t v)`\n\n\u003e Encodes the lowest 57 bits of a signed integer into a 64-bit signed integer.\n\u003e\n\u003e If the argument `v` is a constant expression, then the call to this function is a constant expression as well.\n\u003e\n\u003e For `x != y`, applying this function to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n\u003c!---cpp end---\u003e\n\n## C/C++ macros\n\nThese macros can be used in C89 and newer. C++ code should use the safer C++\nfunctions above instead.\n\n\u003c!---macros start---\u003e\n\n#### `SECDED_4_BITS_TO_UNSIGNED_8(v)`\n\n\u003e Encodes the lowest 4 bits of an unsigned integer into a 8-bit unsigned integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_4_BITS_TO_SIGNED_8(v)`\n\n\u003e Encodes the lowest 4 bits of a signed integer into a 8-bit signed integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_4_BITS_TO_UNSIGNED_16(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_4_BITS_TO_SIGNED_16(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_4_BITS_TO_UNSIGNED_32(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `SECDED_4_BITS_TO_SIGNED_32(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `SECDED_4_BITS_TO_UNSIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.\n\n#### `SECDED_4_BITS_TO_SIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 32 bits, and these differences are distributed across at least 8 bytes.\n\n#### `SECDED_11_BITS_TO_UNSIGNED_16(v)`\n\n\u003e Encodes the lowest 11 bits of an unsigned integer into a 16-bit unsigned integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_11_BITS_TO_SIGNED_16(v)`\n\n\u003e Encodes the lowest 11 bits of a signed integer into a 16-bit signed integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_11_BITS_TO_UNSIGNED_32(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_11_BITS_TO_SIGNED_32(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_11_BITS_TO_UNSIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `SECDED_11_BITS_TO_SIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 16 bits, and these differences are distributed across at least 4 bytes.\n\n#### `SECDED_26_BITS_TO_UNSIGNED_32(v)`\n\n\u003e Encodes the lowest 26 bits of an unsigned integer into a 32-bit unsigned integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_26_BITS_TO_SIGNED_32(v)`\n\n\u003e Encodes the lowest 26 bits of a signed integer into a 32-bit signed integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_26_BITS_TO_UNSIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_26_BITS_TO_SIGNED_64(v)`\n\n\u003e 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.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 8 bits, and these differences are distributed across at least 2 bytes.\n\n#### `SECDED_57_BITS_TO_UNSIGNED_64(v)`\n\n\u003e Encodes the lowest 57 bits of an unsigned integer into a 64-bit unsigned integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n#### `SECDED_57_BITS_TO_SIGNED_64(v)`\n\n\u003e Encodes the lowest 57 bits of a signed integer into a 64-bit signed integer.\n\u003e\n\u003e Be aware that this is a macro that may evaluate `v` multiple times.\n\u003e\n\u003e For `x != y`, applying this macro to `x` and `y` separately will result in two values that differ in at least 4 bits.\n\n\u003c!---macros end---\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftniessen%2Fconstexpr-secded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftniessen%2Fconstexpr-secded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftniessen%2Fconstexpr-secded/lists"}