ACF $AcfVersion:0$
CBitManip.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QtGlobal>
7
8
9namespace istd
10{
11
12
17{
18public:
20
24 int GetFirstBitIndex(quint32 bits) const;
25
27
28private:
29 qint8 m_firstBitInByte[256];
30};
31
32
33// inline methods
34
35inline int CBitManip::GetFirstBitIndex(quint32 bits) const
36{
37 if (bits == 0) {
38 return -1;
39 }
40
41 quint8 b0 = static_cast<quint8>(bits & 0xFFu);
42 if (b0 != 0){
43 return int(m_firstBitInByte[b0]);
44 }
45
46 quint8 b1 = static_cast<quint8>((bits >> 8) & 0xFFu);
47 if (b1 != 0) {
48 return int(m_firstBitInByte[b1]) + 8;
49 }
50
51 quint8 b2 = static_cast<quint8>((bits >> 16) & 0xFFu);
52 if (b2 != 0){
53 return int(m_firstBitInByte[b2]) + 16;
54 }
55
56 quint8 b3 = static_cast<quint8>((bits >> 24) & 0xFFu);
57 if (b3 != 0) {
58 return int(m_firstBitInByte[b3]) + 24;
59 }
60
61 return -1;
62}
63
64
65} // namespace istd
66
67
68
69
Helper class for bits manipulations.
Definition CBitManip.h:17
int GetFirstBitIndex(quint32 bits) const
Return index of first bit in byte.
Definition CBitManip.h:35
static CBitManip instance
Definition CBitManip.h:26
Standard library.
Definition IComponent.h:17