# Program to clear nth bit of a Number

## Problem Statement:- Program to Clear the nth bit of a Number.

#### Sample Input/Output:-

 Sample Input First:6/Number1//Position/*6 Binary=>0110*/ Sample Output First: 4/*4 Binary=>0100*/ Sample Input Second: 17//Number0//Position/*17 Binary=>010001*/ Sample Output Second: 16/*16 Binary=>010000*/

#### Data requirement:-

Input Data:- number, bit_pos

Output Data:-number

Program in C

Code:

Program in C++

## Here is the source code of the C++ Program to clear the nth bit of a number.

Code:

### ``import java.util.Scanner;public class ClearNthBit {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        /* Get the number input */        System.out.print("Enter the Number:");        int number = sc.nextInt();        /* Get the bit position input */        System.out.print("Enter the Bit position you want to clear(Between 0-31):");        int bit_pos = sc.nextInt();        /* Calculating the bit mask */        int mask = (1 << bit_pos);        /* ~(Invert sign, it's convert o to 1 or 1 to 0.) */        number = number & (~mask);        System.out.print("The number after clear the bit in the given position is: " + number);        sc.close();    }}``Input/Output:Enter the Number:63Enter the Bit position you want to clear(Between 0-31):5The number after clear the bit in the given position is: 31

Program in Python

Code: