Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of BIT() in this linux kernel macro?

I was browsing the Linux kernel code and in the file hid.h, the HID_QUIRK_ALWAYS_POLL macro is defined as:

#define HID_QUIRK_ALWAYS_POLL   BIT(10)

What is the meaning of BIT(10)? I am not really familiar with C but from what I know (and researched) there is no such bit manipulation function.

like image 800
kingJulian Avatar asked Jun 13 '18 12:06

kingJulian


2 Answers

looks like you can find the answer inside the first header file included, i.e. bitops.h!

#define BIT(nr) (1UL << (nr))

i.e. BIT defines a bit mask for the specified bit number from 0 (least significant, or rightmost bit) to whatever fits into an unsigned long.
So BIT(10) should evaluate to the numeric value of 1024 (which is 1 << 10).

like image 129
Alex Traud Avatar answered Nov 18 '22 08:11

Alex Traud


BIT is a macro defined in include/linux/bitops.h in the kernel tree:

#define BIT(nr)         (1UL << (nr))

So BIT(10) is basically an unsigned long with tenth bit set.

like image 32
sdobak Avatar answered Nov 18 '22 10:11

sdobak