24constexpr T
mask(
unsigned bits_to_extract )
26 return bits_to_extract <= 1u ? T{1} :
27 static_cast<T
>((mask<T>(bits_to_extract-1) << 1) | T{1});
34struct bits_count<
std::uint8_t> {
static constexpr unsigned count = 8u; };
37struct bits_count<
std::int8_t> {
static constexpr unsigned count = 8u; };
40struct bits_count<char> {
static constexpr unsigned count = 8u; };
43struct bits_count<
std::uint16_t> {
static constexpr unsigned count = 16u; };
46struct bits_count<
std::int16_t> {
static constexpr unsigned count = 16u; };
49struct bits_count<
std::uint32_t> {
static constexpr unsigned count = 32u; };
52struct bits_count<
std::int32_t> {
static constexpr unsigned count = 32u; };
55struct bits_count<
std::uint64_t> {
static constexpr unsigned count = 64u; };
58struct bits_count<
std::int64_t> {
static constexpr unsigned count = 64u; };
84 typename F =
unsigned int >
88 return static_cast<T
>(value >> Shift) & details::mask<T>(Bits_To_Extract);
constexpr T mask(unsigned bits_to_extract)
T n_bits_from(F value)
Extract N bits from a bigger integer value.