X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=2020-frama-c%2F5000-power-of-2.html;fp=2020-frama-c%2F5000-power-of-2.html;h=ccc37599c67d7f2cd0d4c835dafe7d8e0e560e1b;hb=b418766b4d897080ff67a6bd3bb558b14ec985d4;hp=0000000000000000000000000000000000000000;hpb=062da27127bc876eaeb4c728ed50bf744a3bcaa7;p=libguestfs-talks.git diff --git a/2020-frama-c/5000-power-of-2.html b/2020-frama-c/5000-power-of-2.html new file mode 100644 index 0000000..ccc3759 --- /dev/null +++ b/2020-frama-c/5000-power-of-2.html @@ -0,0 +1,18 @@ + + + + +

nbdkit is_power_of_2

+ +
+  /* Returns true if v is a power of 2.
+   *
+   * Uses the algorithm described at
+   * http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
+   */
+  static inline bool
+  is_power_of_2 (unsigned long v)
+  {
+    return v && ((v & (v - 1)) == 0);
+  }
+