summaryrefslogtreecommitdiff
path: root/bitround.c
diff options
context:
space:
mode:
Diffstat (limited to 'bitround.c')
-rw-r--r--bitround.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/bitround.c b/bitround.c
new file mode 100644
index 0000000..4602387
--- /dev/null
+++ b/bitround.c
@@ -0,0 +1,25 @@
+#include <u.h>
+#include <libc.h>
+
+#define round(s, sz) ((s)+((sz)-1)&~((sz)-1))
+
+static void
+usage(void)
+{
+ fprint(2, "usage: bitround number\n");
+ exits("usage");
+}
+
+void
+main(int argc, char *argv[])
+{
+ int i;
+
+ if(argc != 2)
+ usage();
+ i = strtol(argv[1], nil, 0);
+ print("i0 %b (%d)\n", i, i);
+ i = round(i, sizeof(int));
+ print("i1 %b (%d)\n", i, i);
+ exits(0);
+}