mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-25 09:50:59 -04:00
bitwise scripts fixed
This commit is contained in:
parent
01703751f1
commit
91825867f6
25 changed files with 96 additions and 335 deletions
|
@ -8,18 +8,14 @@ __author__ = "bt3"
|
|||
1) Shifts 1 over by i bits
|
||||
2) make an OR with the number, only the value at bit i will change and all the others bit
|
||||
of the mask are zero so will not affect the num
|
||||
|
||||
'''
|
||||
|
||||
|
||||
|
||||
def set_bit(num, i):
|
||||
mask = 1 << i
|
||||
return bin( num | mask )
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
num = int('0100100', 2)
|
||||
print set_bit(num, 0) #'0b100101'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue