🏣 Clean up for arxiv

This commit is contained in:
Mia von Steinkirch 2020-03-04 17:47:53 -08:00
parent 1b969e7db3
commit 41756cb10c
280 changed files with 2 additions and 11 deletions

View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
__author__ = "bt3"
''' This method merges set bit and clean bit:
1) first clear the bit at i using a mask such as 1110111
2) then shift the intended value v by i bits
3) this will create a number with bit i to v and all other to 0
4) finally update the ith bit with or
'''
def update_bit(num, i, v):
mask = ~ (1 << i)
return bin( (num & mask) | (v << i) )
if __name__ == '__main__':
num = int('10010000', 2)
print update_bit(num, 2, 1) # '0b10010100'