mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-10-06 05:39:30 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
7f6082004e
commit
c1a52b40ab
|
@ -1,5 +1,5 @@
|
||||||
def update_bit(n: int, pos: int, value: int) -> int:
|
def update_bit(n: int, pos: int, value: int) -> int:
|
||||||
'''
|
"""
|
||||||
It is a program to update a bit at given position
|
It is a program to update a bit at given position
|
||||||
|
|
||||||
Details:update the bit at position pos of the
|
Details:update the bit at position pos of the
|
||||||
|
@ -16,12 +16,13 @@ def update_bit(n: int, pos: int, value: int) -> int:
|
||||||
7
|
7
|
||||||
>>> update_bit(10,0,1) #0b1011
|
>>> update_bit(10,0,1) #0b1011
|
||||||
11
|
11
|
||||||
'''
|
"""
|
||||||
|
|
||||||
mask = ~(1 << pos)
|
mask = ~(1 << pos)
|
||||||
n = n & mask
|
n = n & mask
|
||||||
return n | (value << pos)
|
return n | (value << pos)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user