Skip to content

Commit 9846e3c

Browse files
committed
Add another bitwise example
1 parent 6b87d51 commit 9846e3c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ultimatepython/syntax/bitwise.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def main():
4040
result_right_shift = a >> 1 # Binary: 0010 (Decimal: 2)
4141
assert result_right_shift == 2
4242

43+
# Note that bitwise shifts have lower precedence than arithmetic operations
44+
# https://docs.python.org/3/reference/expressions.html
45+
result_right_shift_with_addition = a >> 1 + 1 # Equivalent to a >> (1 + 1)
46+
assert result_right_shift_with_addition == 1 # Binary: 0001 (Decimal: 1)
47+
4348

4449
if __name__ == "__main__":
4550
main()

0 commit comments

Comments
 (0)