QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Clear ith bit

Clear the ith bit of a number and returns the resulting number

  • bit-manipulation
  • number
  • clear

Code

int clear_ith_bit(int n, int i) {
    return n & ~(1 << i);
}

Usage

clear_ith_bit(10, 1); // Returns: 8
clear_ith_bit(10, 3); // Returns: 2