tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
test_bit.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_BIT_TEST_BIT_HPP
4
#define TETL_BIT_TEST_BIT_HPP
5
6
#include <
etl/_concepts/builtin_unsigned_integer.hpp
>
7
#include <
etl/_contracts/check.hpp
>
8
#include <
etl/_cstddef/size_t.hpp
>
9
#include <
etl/_limits/numeric_limits.hpp
>
10
11
namespace
etl
{
12
18
template
<etl::builtin_
unsigned
_
int
eger UInt>
19
[[nodiscard]]
constexpr
auto
test_bit
(UInt word, UInt pos)
noexcept
->
bool
20
{
21
TETL_PRECONDITION
(
static_cast<
int
>
(pos) <
etl::numeric_limits<UInt>::digits
);
22
return
static_cast<
UInt
>
(word &
static_cast<
UInt
>
(UInt(1) << pos)) != UInt(0);
23
}
24
29
template
<etl::
size_t
Pos, etl::builtin_
unsigned
_
int
eger UInt>
30
[[nodiscard]]
constexpr
auto
test_bit
(UInt word)
noexcept
->
bool
31
{
32
static_assert
(Pos < etl::numeric_limits<UInt>::digits);
33
return
etl::test_bit
(word,
static_cast<
UInt
>
(Pos));
34
}
35
36
}
// namespace etl
37
38
#endif
// TETL_BIT_TEST_BIT_HPP
builtin_unsigned_integer.hpp
check.hpp
TETL_PRECONDITION
#define TETL_PRECONDITION(...)
Definition
check.hpp:16
etl::test_bit
constexpr auto test_bit(UInt word, UInt pos) noexcept -> bool
Test bit at position pos.
Definition
test_bit.hpp:19
etl
Definition
adjacent_find.hpp:8
numeric_limits.hpp
size_t.hpp
etl::numeric_limits::digits
static constexpr int digits
Definition
numeric_limits.hpp:24
include
etl
_bit
test_bit.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0