diff --git a/Makefile b/Makefile index 60acaea..4d229a0 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ CFLAGS += -Iinclude CFLAGS += -Wall -Wundef -Wextra -Wshadow -Wimplicit-function-declaration CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes +obj-y += source/bitops.o obj-y += source/bitset.o obj-y += source/main.o obj-y += source/shell/cmd.o diff --git a/include/bitops.h b/include/bitops.h new file mode 100644 index 0000000..abee5a9 --- /dev/null +++ b/include/bitops.h @@ -0,0 +1,3 @@ +#pragma once + +unsigned ilog2(unsigned n); diff --git a/source/bitops.c b/source/bitops.c new file mode 100644 index 0000000..59048e2 --- /dev/null +++ b/source/bitops.c @@ -0,0 +1,11 @@ +#include + +unsigned ilog2(unsigned n) +{ + unsigned ret = 0; + + while (n >>= 1) + ++ret; + + return ret; +}