Browse Source

Adding a new macro to be able to determine if a given integer value is a power of 2

etagle 8 years ago
parent
commit
b4c53af07d
1 changed files with 3 additions and 0 deletions
  1. 3
    0
      Marlin/macros.h

+ 3
- 0
Marlin/macros.h View File

@@ -99,6 +99,9 @@
99 99
 #define CBI(n,b) (n &= ~_BV(b))
100 100
 #define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (_BV(b))
101 101
 
102
+// Macro to check that a number if a power if 2
103
+#define IS_POWEROF2(x) ((x) && !((x) & ((x) - 1)))
104
+
102 105
 // Macros for maths shortcuts
103 106
 #ifndef M_PI
104 107
   #define M_PI 3.14159265358979323846

Loading…
Cancel
Save