aboutsummaryrefslogtreecommitdiff
path: root/2.9.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
commitc24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch)
tree460a005b6a3a9a967bd881bc2bf01e0becbe33cc /2.9.c
inital commit
Diffstat (limited to '2.9.c')
-rw-r--r--2.9.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/2.9.c b/2.9.c
new file mode 100644
index 0000000..5a0ceb9
--- /dev/null
+++ b/2.9.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int bitcount(unsigned num);
+
+int
+main(void)
+{
+ int x = 1337; /* a random int */
+ printf("%d\n", bitcount(x));;
+
+ return 0;
+}
+
+int
+bitcount(unsigned num)
+{
+ int bits;
+
+ for (bits = 0; num != 0; num &= (num-1))
+ bits++;
+
+ return bits;
+}