bitops: add ilog2()
This commit is contained in:
parent
5387c2cdb7
commit
7be9d0f049
3 changed files with 15 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -16,6 +16,7 @@ CFLAGS += -Iinclude
|
||||||
CFLAGS += -Wall -Wundef -Wextra -Wshadow -Wimplicit-function-declaration
|
CFLAGS += -Wall -Wundef -Wextra -Wshadow -Wimplicit-function-declaration
|
||||||
CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
|
CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
obj-y += source/bitops.o
|
||||||
obj-y += source/bitset.o
|
obj-y += source/bitset.o
|
||||||
obj-y += source/main.o
|
obj-y += source/main.o
|
||||||
obj-y += source/shell/cmd.o
|
obj-y += source/shell/cmd.o
|
||||||
|
|
3
include/bitops.h
Normal file
3
include/bitops.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
unsigned ilog2(unsigned n);
|
11
source/bitops.c
Normal file
11
source/bitops.c
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include <bitops.h>
|
||||||
|
|
||||||
|
unsigned ilog2(unsigned n)
|
||||||
|
{
|
||||||
|
unsigned ret = 0;
|
||||||
|
|
||||||
|
while (n >>= 1)
|
||||||
|
++ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue