bit
Utility functions for manipulating binary numbers.
A reverse engineered version of C++20’s and C++23’s <bit> header.
bit_cast
template <typename TDestination, typename TSource>
ETL_CONSTEXPR14 TDestination bit_cast(const TSource& source) ETL_NOEXCEPTDescription
Returns a value of type TDestination by reinterpreting the TSource object.
byteswap
template <typename T>
ETL_CONSTEXPR14 T byteswap(T n) ETL_NOEXCEPTDescription
Reverses the bytes in n.
has_single_bit
template <typename T>
ETL_CONSTEXPR14 bool has_single_bit(T n) ETL_NOEXCEPTDescription
Checks if n is a power of two, or has one bit set.
bit_ceil
template <typename T>
ETL_CONSTEXPR14 T bit_ceil(T n)Description
Calculates the smallest power of two, that is not smaller than n.
bit_floor
template <typename T>
ETL_CONSTEXPR14 T bit_floor(T n) ETL_NOEXCEPTDescription
Calculates the largest power of two that is not greater than n.
bit_width
template <typename T>
ETL_CONSTEXPR14 T bit_width(T n) ETL_NOEXCEPTDescription
If n is not 0, calculates the number of bits needed to store it.
If n is 0, then the result is 0.
rotl
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 T rotl(T value, int n) ETL_NOEXCEPTDescription
Computes a left circular shift of value by n.
rotr
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 T rotr(T value, int n) ETL_NOEXCEPTDescription
Computes a right circular shift of value by n.
countl_zero
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countl_zero(T value) ETL_NOEXCEPTDescription
Returns the number of consecutive 0 bits in n, starting from the most significant bit (left).
countl_one
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countl_one(T value) ETL_NOEXCEPTDescription
Returns the number of consecutive 1 bits in n, starting from the most significant bit (left).
countr_zero
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countr_zero(T value) ETL_NOEXCEPTDescription
Returns the number of consecutive 0 bits in n, starting from the least significant bit (right).
countr_one
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countr_one(T value) ETL_NOEXCEPTDescription
Returns the number of consecutive 1 bits in n, starting from the least significant bit (right).
popcount
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int popcount(T value) ETL_NOEXCEPTDescription
Counts the number of 1 bits in an unsigned integer.