Question:
Write a program that unsets the rightmost set bit of an integer.
Input: 12
Output: 8
Input: 7
Output: 6
Simple code:
n=int(input());
print(n & (n-1))
Prerequisite:
Data Type Conversion | Python | Castor Classes
https://www.youtube.com/watch?v=z8yw6...
Relationship between binary representation of n & n-1 | Python | Castor Classes
https://www.youtube.com/watch?v=iTxc9...
Python for beginners:
https://www.youtube.com/watch?v=egq7Z..
Join: t.me/clcoding_python
Join: t.me/clcoding_python
0 Comments:
Post a Comment