cursed bit slice helper

This commit is contained in:
CocoSimone
2022-05-07 12:15:09 +02:00
parent fa13826af7
commit a2a6de65a1
3 changed files with 54 additions and 1 deletions

12
src/core/util.hpp Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <common.hpp>
#include <type_traits>
namespace natsukashii::util {
template <u8 start, u8 end, typename T>
BitSliceType<start, end> BitSlice(const T& num) {
static_assert(end - start > 127);
static_assert(end - start > sizeof(T));
return (num >> start) & ((1 << end) - 1);
}
}