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 variableaand assigns it the binary value1010.let b = 0b1100;: This line declares a variableband assigns it the binary value1100.let result = a ^ b;: This line performs a bitwise exclusive OR operation onaandb, 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 a capture group using Rust regex?
- Regex example to match multiline string in Rust?
- How to use regex lookbehind in Rust?
- How to match the end of a line in a Rust regex?
- How to use regex to match a double quote in Rust?
- How to use regex captures in Rust?
- How to perform matrix operations in Rust?
- How to use non-capturing groups in Rust regex?
- How to print a Rust HashMap?
- How to compare two HashSets in Rust?
See more codes...