{"id":8480,"date":"2021-08-16T14:13:33","date_gmt":"2021-08-16T08:43:33","guid":{"rendered":"https:\/\/python-programs.com\/?p=8480"},"modified":"2021-11-22T18:39:25","modified_gmt":"2021-11-22T13:09:25","slug":"program-to-clear-the-rightmost-set-bit-of-a-number-in-cpp-and-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-to-clear-the-rightmost-set-bit-of-a-number-in-cpp-and-python\/","title":{"rendered":"Program to Clear the Rightmost Set Bit of a Number in C++ and Python"},"content":{"rendered":"

In the previous article, we have discussed about C++ Program to Check if it is Sparse Matrix or Not<\/a>. Let us learn Program to Clear the Rightmost Set Bit of a Number in C++ Program and Python.<\/p>\n

Binary Representation of a Number:<\/strong><\/p>\n

Binary is a base-2 number system in which a number is represented by two states: 0 and 1. We can also refer to it as a true and false state. A binary number is constructed in the same way that a decimal number is constructed.<\/p>\n

Examples:<\/strong><\/p>\n

Examples1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number=19<\/p>\n

Output:<\/strong><\/p>\n

The given number before removing right most set bit : \r\n19\r\nThe given number after removing right most set bit : \r\n18<\/pre>\n

Examples2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number =18<\/pre>\n

Output:<\/strong><\/p>\n

The given number before removing right most set bit : \r\n18\r\nThe given number after removing right most set bit : \r\n16<\/pre>\n

Examples3:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number=512<\/pre>\n

Output:<\/strong><\/p>\n

The given number before removing right most set bit : \r\n512\r\nThe given number after removing right most set bit : \r\n0<\/pre>\n

Program to Clear the Rightmost Set Bit of a Number in C++ and Python<\/h2>\n

There are several ways to clear the rightmost set Bit of a Number in C++ and Python some of them are:<\/p>\n