summaryrefslogtreecommitdiff
path: root/bitround.c
blob: 4602387e7018a3cad915581b8ba4757383beeed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}