Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 0 years ago

Max Alekseyev gravatar image

Test test test

click to hide/show revision 2
No.2 Revision

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

click to hide/show revision 3
No.3 Revision

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
click to hide/show revision 4
No.4 Revision

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/

click to hide/show revision 5
No.5 Revision

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/

click to hide/show revision 6
No.6 Revision

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/