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 convert the keys of a Rust HashMap to a vector?
- How to calculate the inverse of a matrix in Rust?
- How to modify an existing entry in a Rust HashMap?
- Hashshet example in Rust
- How to match the end of a line in a Rust regex?
- How to use an enum in a Rust HashMap?
- How to convert a Rust slice to a fixed array?
- How to replace all matches using Rust regex?
- How to convert a Rust HashMap to a JSON string?
- How to create a subslice from a Rust slice?
See more codes...