SUNphi  1.0
Bits.hpp
Go to the documentation of this file.
1 #ifndef _BITS_HPP
2 #define _BITS_HPP
3 
4 /// \file Bits.hpp
5 ///
6 /// \brief Access a variable by bit
7 ///
8 
9 #include <bitset>
10 
11 #include <metaprogramming/UniversalReferences.hpp>
12 
13 namespace SUNphi
14 {
15  /// Access to a given bit of a variable
16  template <typename T> // Type of the variable
17  bool bitOf(const T& in, ///< Input variable
18  const int pos) ///< Bit to take
19  {
20  /// Size of the bitset
21  constexpr int bitsetSize=
22  sizeof(T);
23 
24  /// Bitset view of the variable
25  using B=
26  std::bitset<bitsetSize>;
27 
28  return
29  static_cast<const B>(in)[pos];
30  }
31 
32  /// Access to the lowest bit of a variable
33  template <typename T> // Type of the variable
34  bool lowestBitOf(const T& in) ///< Input variable
35  {
36  return bitOf(in,0);
37  }
38 }
39 
40 #endif
bool bitOf(const T &in, const int pos)
Access to a given bit of a variable.
Definition: Bits.hpp:17
bool lowestBitOf(const T &in)
Access to the lowest bit of a variable.
Definition: Bits.hpp:34