namespace roast
{
- template <typename T>
- T bit_extract(const T& target, unsigned int start_bit, unsigned int length)
+ namespace tp
{
- ::std::bitset<sizeof(T) * 8> bs(target);
- T ret;
- for(unsigned int i=start_bit; i < start_bit+length; i++)
+ ////////////////
+
+ template <unsigned int START_BIT, unsigned int LENGTH>
+ struct create_bitmask
{
- ret |= (bs[i] << (i-start_bit));
- }
- return ret;
+ private:
+ template <unsigned int START_BIT_I, unsigned int LENGTH_I>
+ struct _impl
+ {
+ static const int value = (1 << START_BIT_I) +
+ _impl<START_BIT_I+1, LENGTH_I-1>::value;
+ };
+ template <unsigned int START_BIT_I>
+ struct _impl<START_BIT_I, 0>
+ {
+ static const int value = 1 << START_BIT_I;
+ };
+ public:
+ static const int value = _impl<START_BIT, LENGTH>::value;
+ };
+
+ ////////////////
}
}