diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/bits.hpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/base/bits.hpp b/base/bits.hpp index 4c561f3422..94c5d501db 100644 --- a/base/bits.hpp +++ b/base/bits.hpp @@ -2,9 +2,9 @@ #include "base/assert.hpp" #include "std/cstdint.hpp" +#include "std/limits.hpp" #include "std/type_traits.hpp" - namespace bits { // Count the number of 1 bits. Implementation: see Hacker's delight book. @@ -201,4 +201,11 @@ namespace bits while (n != 0) { ++result; n >>= 1; } return result; } -} + + inline uint64_t GetFullMask(uint8_t numBits) + { + ASSERT_LESS_OR_EQUAL(numBits, 64, ()); + return numBits == 64 ? numeric_limits<uint64_t>::max() + : (static_cast<uint64_t>(1) << numBits) - 1; + } +} // namespace bits |