Back
Close

Rust for Python Developers - Operators

Shin_O
4,692 views
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

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants