Skip to content
Browse files

value -> nb bits mask

  • Loading branch information...
1 parent b70a426 commit 8457bc360c533d497aa620435df5238ae1c5563f @jpbillaud committed
Showing with 12 additions and 0 deletions.
  1. +12 −0 bits/value_to_nb_bits.c
View
12 bits/value_to_nb_bits.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+/*
+ * Write a function that given an integer ranging from 0 to 32 generates
+ * a bit mask with that many bits.
+ */
+
+unsigned int
+value_to_nb_bits(unsigned int value)
+{
+ return ((long long unsigned int)1 << value) - 1;
+}

0 comments on commit 8457bc3

Please sign in to comment.
Something went wrong with that request. Please try again.