A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove

Bit

Utility functions for manipulating binary numbers.
A reverse engineered version of C++20's and C++23's <bit> header.

ETL_CONSTEXPR14 = constexpr for C++14  or above
____________________________________________________________________________________________________
template <typename TDestination, typename TSource>>
ETL_CONSTEXPR14 TDestination bit_cast(const TDestination& source) ETL_NOEXCEPT
Returns a value of type TDestination by reinterpreting the TSource object.
____________________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR14 T byteswap(T n) ETL_NOEXCEPT
Reverses the bytes in n.
____________________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR14 bool has_single_bit(T n) ETL_NOEXCEPT
Checks if n is a power of two, or has one bit set.
____________________________________________________________________________________________________ 
template <typename T>
ETL_CONSTEXPR14 T bit_ceil(T n);
Calculates the smallest power of two, that is not smaller than n.
____________________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR14 T bit_floor(T n) ETL_NOEXCEPT
Calculates the smallest power of two, that is not greater than n.
____________________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR14 T bit_width(T n) ETL_NOEXCEPT
If n is not 0, calculates the number of bits needed to store it.
If n is 0, then the result is 0.
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 T rotl(T value, int n) ETL_NOEXCEPT
Computes a left circular shift of value by n.
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 T rotr(T value, int n) ETL_NOEXCEPT
Computes a right circular shift of value by n.
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countl_zero(T value) ETL_NOEXCEPT
Returns the number of consecutive 0 bits in n, starting from the most significant bit (left).
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countl_one(T value) ETL_NOEXCEPT
Returns the number of consecutive 1 bits in n, starting from the most significant bit (left).
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countr_zero(T value) ETL_NOEXCEPT
Returns the number of consecutive 0 bits in n, starting from the least significant bit (right).
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int countr_one(T value) ETL_NOEXCEPT
Returns the number of consecutive 1 bits in n, starting from the least significant bit (right).
____________________________________________________________________________________________________
template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 int popcount(T value) ETL_NOEXCEPT
Counts the number of 1 bits in an unsigned integer.
bit.h