From 3062a29b787d48db5c1528a15d4688c2b761d6b7 Mon Sep 17 00:00:00 2001 From: joevt Date: Mon, 18 Sep 2023 16:07:42 -0700 Subject: [PATCH] Add clear_bit and set_bit. --- core/bitops.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/bitops.h b/core/bitops.h index 72f0384..eaff2c6 100644 --- a/core/bitops.h +++ b/core/bitops.h @@ -78,4 +78,14 @@ static inline bool bit_set(const uint64_t val, const int bit_num) { return !!(val & (1ULL << bit_num)); } +template +inline void clear_bit(T &val, const int bit_num) { + val &= ~((T)1 << bit_num); +} + +template +inline void set_bit(T &val, const int bit_num) { + val |= ((T)1 << bit_num); +} + #endif // BIT_OPS_H