rustBitwise XOR operator usage in Rust
The bitwise XOR operator (^
) is a binary operator in Rust that performs a bitwise exclusive OR operation on two operands. It returns a result that has a bit set if either, but not both, of the corresponding bits of the two operands is set.
Example
let a = 0b1010;
let b = 0b1100;
let result = a ^ b;
println!("{:b}", result);
Output example
0110
Code explanation
let a = 0b1010;
: This line declares a variablea
and assigns it the binary value1010
.let b = 0b1100;
: This line declares a variableb
and assigns it the binary value1100
.let result = a ^ b;
: This line performs a bitwise exclusive OR operation ona
andb
, and assigns the result to the variableresult
.println!("{:b}", result);
: This line prints the binary representation of the result of the bitwise exclusive OR operation.
Helpful links
Related
More of Rust
- How to replace strings using Rust regex?
- How to convert a Rust HashMap to a BTreeMap?
- How to get a capture group using Rust regex?
- How do I identify unused variables in Rust?
- How to parse JSON string in Rust?
- How to convert a Rust HashMap to JSON?
- How to replace a capture group using Rust regex?
- Hashshet example in Rust
- How to use non-capturing groups in Rust regex?
- How to match the end of a line in a Rust regex?
See more codes...