8namespace Stroika::Foundation::Memory {
15 template <
integral INT_TYPE>
16 inline constexpr INT_TYPE
Bit (
unsigned int bitNumber)
18 Require (bitNumber < CHAR_BIT *
sizeof (INT_TYPE));
19 return static_cast<INT_TYPE
> (1) << bitNumber;
21 template <integral INT_TYPE, integral... BIT_ARGS>
22 inline constexpr INT_TYPE Bit (
unsigned int bitNumber,
const BIT_ARGS&... args)
24 return Bit<INT_TYPE> (bitNumber) | Bit<INT_TYPE> (args...);
32 template <
integral INT_TYPE>
33 inline constexpr INT_TYPE
BitSubstring (INT_TYPE bitField,
unsigned int startOffset,
unsigned int endOffset)
35 Require (startOffset <= endOffset);
36 Require (startOffset <= (CHAR_BIT *
sizeof (INT_TYPE)));
37 if (startOffset == endOffset) {
40 Require (((endOffset - startOffset) - 1 + startOffset) < (CHAR_BIT *
sizeof (INT_TYPE)));
41 return (bitField >> startOffset) & ((1 << (endOffset - startOffset)) - 1);
constexpr INT_TYPE Bit(unsigned int bitNumber)
constexpr INT_TYPE BitSubstring(INT_TYPE bitField, unsigned int startOffset, unsigned int endOffset)