FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/algorithms/bit/remove_bit.py at master · pk210700/algorithms · GitHub
pk210700
algorithms
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
algorithms
/
bit
/
remove_bit.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
15 lines (13 loc) · 344 Bytes
Breadcrumbs
algorithms
/
algorithms
/
bit
/
remove_bit.py
Copy path
File metadata and controls
15 lines (13 loc) · 344 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"""
Remove_bit(num, i): remove a bit at specific position.
For example:
Input: num = 10101 (21)
remove_bit(num, 2): output = 1001 (9)
remove_bit(num, 4): output = 101 (5)
remove_bit(num, 0): output = 1010 (10)
"""
def
remove_bit
(
num
,
i
):
mask
=
num
>>
(
i
+
1
)
mask
=
mask
<<
i
right
=
((
1
<<
i
)
-
1
)
&
num
return
mask
|
right
Back
|
FazBrowse Home
|
New Git URL