tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
countl_one.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_BIT_COUNTL_ONE_HPP
4#define TETL_BIT_COUNTL_ONE_HPP
5
8
9namespace etl {
10
22template <etl::builtin_unsigned_integer UInt>
23[[nodiscard]] constexpr auto countl_one(UInt x) noexcept -> int
24{
25 auto const totalBits = etl::numeric_limits<UInt>::digits;
27 return totalBits;
28 }
29
30 auto res = 0;
31 while (x & (UInt(1) << (static_cast<UInt>(totalBits) - UInt(1)))) {
32 x = static_cast<UInt>(x << UInt(1));
33 ++res;
34 }
35
36 return res;
37}
38
39} // namespace etl
40
41#endif // TETL_BIT_COUNTL_ONE_HPP
constexpr auto countl_one(UInt x) noexcept -> int
Returns the number of consecutive 1 ("one") bits in the value of x, starting from the most significan...
Definition countl_one.hpp:23
Definition adjacent_find.hpp:8
static constexpr int digits
Definition numeric_limits.hpp:24
static constexpr auto max() noexcept
Definition numeric_limits.hpp:21