tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
countl_zero.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_BIT_COUNTL_ZERO_HPP
4
#define TETL_BIT_COUNTL_ZERO_HPP
5
6
#include <
etl/_concepts/builtin_unsigned_integer.hpp
>
7
#include <
etl/_limits/numeric_limits.hpp
>
8
9
namespace
etl
{
10
22
template
<etl::builtin_
unsigned
_
int
eger UInt>
23
[[nodiscard]]
constexpr
auto
countl_zero
(UInt x)
noexcept
->
int
24
{
25
auto
const
totalBits =
etl::numeric_limits<UInt>::digits
;
26
if
(x == UInt(0)) {
27
return
etl::numeric_limits<UInt>::digits
;
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_ZERO_HPP
builtin_unsigned_integer.hpp
etl::countl_zero
constexpr auto countl_zero(UInt x) noexcept -> int
Returns the number of consecutive 0 bits in the value of x, starting from the most significant bit ("...
Definition
countl_zero.hpp:23
etl
Definition
adjacent_find.hpp:8
numeric_limits.hpp
etl::numeric_limits::digits
static constexpr int digits
Definition
numeric_limits.hpp:24
include
etl
_bit
countl_zero.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0