bitops: add ilog2()

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 5387c2cdb7
commit 7be9d0f049
  1. 1
      Makefile
  2. 3
      include/bitops.h
  3. 11
      source/bitops.c

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

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

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