bitops: add ilog2()

This commit is contained in:
S.J.R. van Schaik 2017-04-07 16:32:44 +02:00
parent 5387c2cdb7
commit 7be9d0f049
3 changed files with 15 additions and 0 deletions

View file

@ -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

3
include/bitops.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
unsigned ilog2(unsigned n);

11
source/bitops.c Normal file
View file

@ -0,0 +1,11 @@
#include <bitops.h>
unsigned ilog2(unsigned n)
{
unsigned ret = 0;
while (n >>= 1)
++ret;
return ret;
}