Bit#
Defined in namespace hal
#include <libhal-util/bit.hpp>
- group Bit
Functions
-
template<std::uint32_t position1, std::uint32_t position2>
static inline consteval bit_mask from()# Generate, at compile time, a bit_mask that spans the from position1 to position2.
If position1 is the same position2 then the bit_mask will have length of 1 and the bit position will be the value of position1.
position1 and position2 can be in any order so long as they span the distance from the start and end of the bit_mask range.
-
template<std::uint32_t position>
static inline constexpr bit_mask from()# Generate, at compile time, a single bit width bit_mask at position.
-
static inline consteval bit_mask from(std::uint32_t position1, std::uint32_t position2)#
Generate, at compile time, a bit_mask that spans the from position1 to position2.
If position1 is the same position2 then the bit_mask will have length of 1 and the bit position will be the value of position1.
position1 and position2 can be in any order so long as they span the distance from the start and end of the bit_mask range.
-
static inline constexpr bit_mask from(std::uint32_t position)#
Generate, at runtime, a single bit width bit_mask at position.
-
template<std::unsigned_integral T>
inline constexpr auto origin() const# Convert bit_mask to a integral representation but with bit position at 0.
The integral presentation will have 1 bits starting from the position bit up to bit position + width. All other bits will be 0s.
For example:
value<std::uint16_t>(bit_mask{ .position = 1, .width = 4, }); // returns = 0b0000'0000'0000'1111;
-
template<std::unsigned_integral T>
inline constexpr auto value() const# Convert mask to a integral representation.
The integral presentation will have 1 bits starting from the position bit up to bit position + width. All other bits will be 0s.
For example:
value<std::uint16_t>(bit_mask{ .position = 1, .width = 4, }); // returns = 0b0000'0000'0001'1110;
- Template Parameters:
T – - unsigned integral type to hold the mask
- Returns:
constexpr auto - mask value as an unsigned integer
-
inline constexpr bool operator==(const bit_mask &other)#
Comparison operator between this mask and another.
- Parameters:
other – - the other mask to compare against
- Returns:
true - the masks are the same
- Returns:
false - the masks are not the same
Variables
- static constexpr hal::bit_mask value = { .position = ByteIndex, .width = 8 }
Mask value defined at compile time.
-
template<size_t ByteIndex>
constexpr hal::bit_mask byte_m = byte_mask<ByteIndex>::value# Shorthand for using hal::byte_mask<N>::value.
- Template Parameters:
ByteIndex – - the byte position to make a mask for
-
template<size_t NibbleIndex>
constexpr hal::bit_mask nibble_m = nibble_mask<NibbleIndex>::value# Shorthand for using hal::nibble_mask<N>::value.
- Template Parameters:
NibbleIndex – - the nibble position to make a mask for
-
struct bit_mask#
- #include <bit.hpp>
Represents a bit mask of contiguous bits.
Public Functions
-
template<std::unsigned_integral T>
inline constexpr auto origin() const# Convert bit_mask to a integral representation but with bit position at 0.
The integral presentation will have 1 bits starting from the position bit up to bit position + width. All other bits will be 0s.
For example:
value<std::uint16_t>(bit_mask{ .position = 1, .width = 4, }); // returns = 0b0000'0000'0000'1111;
-
template<std::unsigned_integral T>
inline constexpr auto value() const# Convert mask to a integral representation.
The integral presentation will have 1 bits starting from the position bit up to bit position + width. All other bits will be 0s.
For example:
value<std::uint16_t>(bit_mask{ .position = 1, .width = 4, }); // returns = 0b0000'0000'0001'1110;
- Template Parameters:
T – - unsigned integral type to hold the mask
- Returns:
constexpr auto - mask value as an unsigned integer
Public Members
-
std::uint32_t position#
Where the bit mask starts.
-
std::uint32_t width#
The number of bits after position contained in the mask.
Public Static Functions
-
template<std::uint32_t position1, std::uint32_t position2>
static inline consteval bit_mask from()# Generate, at compile time, a bit_mask that spans the from position1 to position2.
If position1 is the same position2 then the bit_mask will have length of 1 and the bit position will be the value of position1.
position1 and position2 can be in any order so long as they span the distance from the start and end of the bit_mask range.
-
template<std::uint32_t position>
static inline constexpr bit_mask from()# Generate, at compile time, a single bit width bit_mask at position.
-
static inline consteval bit_mask from(std::uint32_t position1, std::uint32_t position2)#
Generate, at compile time, a bit_mask that spans the from position1 to position2.
If position1 is the same position2 then the bit_mask will have length of 1 and the bit position will be the value of position1.
position1 and position2 can be in any order so long as they span the distance from the start and end of the bit_mask range.
-
template<std::unsigned_integral T>
-
template<size_t ByteIndex>
struct byte_mask# - #include <bit.hpp>
Helper for generating byte position masks.
- Template Parameters:
ByteIndex – - the byte position to make a mask for
Public Static Attributes
- static constexpr hal::bit_mask value = { .position = ByteIndex, .width = 8 }
Mask value defined at compile time.
-
template<size_t NibbleIndex>
struct nibble_mask# - #include <bit.hpp>
Helper for generating nibble position masks.
- Template Parameters:
NibbleIndex – - the nibble position to make a mask for
-
template<std::uint32_t position1, std::uint32_t position2>