Skip to content

Commit 3f375be

Browse files
authored
modify update_bit.py
1 parent c1a52b4 commit 3f375be

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

bit_manipulation/update_bit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
def update_bit(n: int, pos: int, value: int) -> int:
1+
def update_bit(number: int, position: int, value: int) -> int:
22
"""
33
It is a program to update a bit at given position
44
5-
Details:update the bit at position pos of the
6-
number n by the value provided to it.
5+
Details:update the bit at position of the
6+
number by the value provided to it.
77
and return updated integer.
88
99
>>> update_bit(5,0,0) #0b100
@@ -18,9 +18,9 @@ def update_bit(n: int, pos: int, value: int) -> int:
1818
11
1919
"""
2020

21-
mask = ~(1 << pos)
22-
n = n & mask
23-
return n | (value << pos)
21+
mask = ~(1 << position)
22+
number = number & mask
23+
return number | (value << position)
2424

2525

2626
if __name__ == "__main__":

0 commit comments

Comments
 (0)