summaryrefslogtreecommitdiff
path: root/bitround.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-02-22 09:56:09 +0000
committerrodri <rgl@antares-labs.eu>2020-02-22 09:56:09 +0000
commita39951d8f69209cfea2b7051832b851914e662ef (patch)
treee4cd1c32e5d6f531b523f6fda558cc3a5f603547 /bitround.c
downloadbrokentoys-a39951d8f69209cfea2b7051832b851914e662ef.tar.gz
brokentoys-a39951d8f69209cfea2b7051832b851914e662ef.tar.bz2
brokentoys-a39951d8f69209cfea2b7051832b851914e662ef.zip
now version controlled.
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);
+}