kingJulian
kingJulian

Reputation: 6170

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.

Upvotes: 11

Views: 17660

Answers (3)

alext
alext

Reputation: 326

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).

Upvotes: 18

sdobak
sdobak

Reputation: 399

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.

Upvotes: 5

Thomas Jager
Thomas Jager

Reputation: 5265

The BIT macro shifts the value 1 left by the value given to it, so BIT(10) == (1 << (10)). It can be used to get a specific boolean value from a bit field.

Upvotes: 0

Related Questions