bitarithm.h¶
Helper functions for bit arithmetic.
-
BIT0
¶ 1
0x00000001
-
BIT1
¶ 1
0x00000002
-
BIT2
¶ 1
0x00000004
-
BIT3
¶ 1
0x00000008
-
BIT4
¶ 1
0x00000010
-
BIT5
¶ 1
0x00000020
-
BIT6
¶ 1
0x00000040
-
BIT7
¶ 1
0x00000080
-
BIT8
¶ 1
0x00000100
-
BIT9
¶ 1
0x00000200
-
BIT10
¶ 1
0x00000400
-
BIT11
¶ 1
0x00000800
-
BIT12
¶ 1
0x00001000
-
BIT13
¶ 1
0x00002000
-
BIT14
¶ 1
0x00004000
-
BIT15
¶ 1
0x00008000
-
BIT16
¶ 1
0x00010000
-
BIT17
¶ 1
0x00020000
-
BIT18
¶ 1
0x00040000
-
BIT19
¶ 1
0x00080000
-
BIT20
¶ 1
0x00100000
-
BIT21
¶ 1
0x00200000
-
BIT22
¶ 1
0x00400000
-
BIT23
¶ 1
0x00800000
-
BIT24
¶ 1
0x01000000
-
BIT25
¶ 1
0x02000000
-
BIT26
¶ 1
0x04000000
-
BIT27
¶ 1
0x08000000
-
BIT28
¶ 1
0x10000000
-
BIT29
¶ 1
0x20000000
-
BIT30
¶ 1
0x40000000
-
BIT31
¶ 1
0x80000000
-
SETBIT
( val, bit)¶ Sets a bitmask for a bitfield.
1
val |= (bit)
Parameters
val: The bitfield bit: Specifies the bits to be set Return values
- The modified bitfield
-
CLRBIT
( val, bit)¶ Clears bitmask for a bitfield.
1
val &= (~(bit))
Parameters
val: The bitfield bit: Specifies the bits to be cleared Return values
- The modified bitfield
-
ARCH_32_BIT
¶ 1 for 32 bit architectures, 0 otherwise
1
(__INT_MAX__ == 2147483647)
-
unsigned
bitarithm_msb
(unsigned v)¶ Returns the number of the highest ‘1’ bit in a value.
Parameters
v: Input value Return values
- Bit Number
-
unsigned
bitarithm_lsb
(unsigned v)¶ Returns the number of the lowest ‘1’ bit in a value.
Parameters
v: Input value - must be unequal to ‘0’, otherwise the function will produce an infinite loop Return values
- Bit Number
-
unsigned
bitarithm_bits_set
(unsigned v)¶ Returns the number of bits set in a value.
Parameters
v: Input value with platform-dependent word size Return values
- Number of set bits
-
uint8_t
bitarithm_bits_set_u32
(uint32_t v)¶ Returns the (uint32_t version) number of bits set in a value.
Parameters
v: Input value with 32 bit size Return values
- Number of set bits