RESTinio

Namespaces | Functions
restinio::utils::impl::bitops Namespace Reference

## Namespaces
namespace | details

## Functions
template<typename T , unsigned Shift, unsigned Bits_To_Extract = details::bits_count<T>::count, typename F = unsigned int>
T | n_bits_from (F value)
| Extract N bits from a bigger integer value. More...

## Function Documentation

## ◆ n_bits_from()

template<typename T , unsigned Shift, unsigned Bits_To_Extract = details::bits_count<T>::count, typename F = unsigned int>

T restinio::utils::impl::bitops::n_bits_from | ( | F | value | ) |

Extract N bits from a bigger integer value.

Usage example:

// Extract 8 bits as unsigned char from bits 24..31 in uint32_t.
const std::uint32_t v1 = some_uint_value();
const auto u8 = n_bits_from<std::uint8_t, 24>(v1);
// Extract 6 bits as char from bits 12..17 in uint32_t.
const auto ch = n_bits_from<char, 12, 6>(v1);
// Extract 4 bits as unsigned int from bits 32..35 in uint64_t.
const std::uint64_t v2 = some_uint64_value();
const auto ui = n_bits_from<unsigned int, 32, 4>(v2);

Definition at line 86 of file bitops.hpp.