CBitManip.h
Go to the documentation of this file.
1 #ifndef istd_CBitManip_included
2 #define istd_CBitManip_included
3 
4 
5 // Qt includes
6 #include <QtCore/QtGlobal>
7 
8 
9 namespace istd
10 {
11 
12 
16 class CBitManip
17 {
18 public:
19  CBitManip();
20 
24  int GetFirstBitIndex(quint32 bits) const;
25 
27 
28 private:
29  qint8 m_firstBitInByte[256];
30 };
31 
32 
33 // inline methods
34 
35 inline int CBitManip::GetFirstBitIndex(quint32 bits) const
36 {
37  quint16* words = (quint16*)&bits;
38  quint8* bytes = (quint8*)&bits;
39  if (words[0] != 0){
40  if (bytes[0] != 0){
41  return int(m_firstBitInByte[bytes[0]]);
42  }
43 
44  return int(m_firstBitInByte[bytes[1]]);
45  }
46  else if (words[1] != 0){
47  if (bytes[2] != 0){
48  return int(m_firstBitInByte[bytes[2]]);
49  }
50 
51  return int(m_firstBitInByte[bytes[3]]);
52  }
53 
54  return -1;
55 }
56 
57 
58 } // namespace istd
59 
60 
61 #endif // !istd_CBitManip_included
62 
63 
Helper class for bits manipulations.
Definition: CBitManip.h:16
static CBitManip instance
Definition: CBitManip.h:26
int GetFirstBitIndex(quint32 bits) const
Return index of first bit in byte.
Definition: CBitManip.h:35

© 2007-2017 Witold Gantzke and Kirill Lepskiy