retdec
math.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_UTILS_MATH_H
8 #define RETDEC_UTILS_MATH_H
9 
10 namespace retdec {
11 namespace utils {
12 
20 template<typename N>
21 bool isPowerOfTwo(N number) {
22  return number && !(number & (number - 1));
23 }
24 
32 template<typename N>
33 bool isPowerOfTwoOrZero(N number) {
34  return !number || isPowerOfTwo(number);
35 }
36 
37 unsigned countBits(unsigned long long n);
38 unsigned bitSizeOfNumber(unsigned long long v);
39 
40 } // namespace utils
41 } // namespace retdec
42 
43 #endif
bool isPowerOfTwoOrZero(N number)
Check if number is power of two or zero.
Definition: math.h:33
unsigned bitSizeOfNumber(unsigned long long v)
Returns the number of bits needed to encode the given number.
Definition: math.cpp:26
unsigned countBits(unsigned long long n)
Counts all 1 bits in the given number.
Definition: math.cpp:15
bool isPowerOfTwo(N number)
Check if number is power of two.
Definition: math.h:21
Definition: archive_wrapper.h:19