Ask Your Question

Revision history [back]

Test test test

Test test testIf I guessed the meaning of your "n.set_bit(7)" correctly, then it can be achieved via Python's bitwise operator | as

If I guessed the meaning of your "n.set_bit(7)" correctly, then it can be achieved via Python's bitwise operator | as

n |= 1<<7


If I guessed the meaning of your "n.set_bit(7)" correctly, then it can be achieved via Python's bitwise operator | as

n |= 1<<7


You can find more details on bitwise operators at

To make ~ work as in Python, convert the argument to int first:

mask = ~int(1 << n)


See also this Q&A: https://ask.sagemath.org/question/23823/

If I guessed the meaning of your "n.set_bit(7)" correctly, then it can be achieved via Python's bitwise operator | as

n |= 1<<7


You can find more details on bitwise operators at https://realpython.com/python-bitwise-operators/

To make ~ work as in Python, convert the argument to int first:

mask = ~int(1 << n)


See also this Q&A: https://ask.sagemath.org/question/23823/

If I guessed the meaning of your "n.set_bit(7)" correctly, then it can be achieved via Python's bitwise operator | as

n |= 1<<7


You can find more details on bitwise operators at https://realpython.com/python-bitwise-operators/

To make ~ work as in Python, convert the argument to int first:

mask = ~int(1 << n)


or as suggested in the comments:

mask = ~(int(1) << n)


or simply

mask = ~(1r << n)


See also this Q&A: https://ask.sagemath.org/question/23823/