is_bit_set


is_bit_set(i, index)
      

Return true if the bit at index of the integer i is set, i.e it is 1. Otherwise return false.

The two's complement representation of a nonnegative number conceptually extends to the left (toward more significant bits) with an infinite number of zero bits, and the two's complement representation of a negative number conceptually extends to the left with an infinite number of one bits.

Examples:


is_bit_set(0b01011, 0)
// true

is_bit_set(0b01011, 2) 
// false

is_bit_set(-1, 0) 
// true

is_bit_set(-1, 20) 
// true

is_bit_set(-3, 1) 
// false

is_bit_set(0, 5000) 
// false

is_bit_set(-1, 5000) 
// true
      

Also see:

is_any_bits_set
is_all_bits_set


Core Module Index | Contents