Rust for Python Developers - Operators

Shin_O
61.3K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
Previous: Operator Overloading Next: Problem 1 Single Number

This article was originally published on Medium

Follow me:

XOR and Bitwise Operators Truth Table

As we saw previously, Python and Rust use the same symbols for bitwise symbols AND, OR , and XOR.

& is the bitwise AND, | is the bitwise OR , and ^ is the bitwise XOR (exclusive OR). You can see the truth table and the Venn diagram below.

abAND: a & bOR: a | bXOR: a ^ b
TT110
TF011
FT111
FF000

and-or-circles-1

When you use XOR with even numbers of the same number, the output is always 0.

In Rust, you can use {:#b} to print binary.

In Python

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content