mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-10-06 05:39:30 +00:00
modify update_bit.py
This commit is contained in:
parent
c1a52b40ab
commit
3f375be2f1
|
@ -1,9 +1,9 @@
|
|||
def update_bit(n: int, pos: int, value: int) -> int:
|
||||
def update_bit(number: int, position: int, value: int) -> int:
|
||||
"""
|
||||
It is a program to update a bit at given position
|
||||
|
||||
Details:update the bit at position pos of the
|
||||
number n by the value provided to it.
|
||||
Details:update the bit at position of the
|
||||
number by the value provided to it.
|
||||
and return updated integer.
|
||||
|
||||
>>> update_bit(5,0,0) #0b100
|
||||
|
@ -18,9 +18,9 @@ def update_bit(n: int, pos: int, value: int) -> int:
|
|||
11
|
||||
"""
|
||||
|
||||
mask = ~(1 << pos)
|
||||
n = n & mask
|
||||
return n | (value << pos)
|
||||
mask = ~(1 << position)
|
||||
number = number & mask
|
||||
return number | (value << position)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user