modify update_bit.py

This commit is contained in:
Legend015 2023-10-06 13:59:57 +05:30 committed by GitHub
parent c1a52b40ab
commit 3f375be2f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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__":