pack_bits()
Set bits to 1 at specified positions
Sets bits to 1 at the specified positions.
constexpr uint32_t pack_bits(...)
Parameters are specified as variadic arguments, each indicating a bit position (integer from 0 to 31). For example, pack_bits(1,3,6)
returns ((1UL<<1)|(1UL<<3)|(1UL<<6))
.
constexpr
enables compile-time evaluation when possible using constant expressions.Background
This function simplifies the notation in situations where values are referenced or set in various bitmaps such as IO port (DI, DO) states.