rustBitwise negation (NOT) usage in Rust
Bitwise negation (NOT) is a unary operator in Rust that performs a bitwise inversion of its operand. It is represented by the !
symbol.
For example, the following code block will invert the bits of the number 5
:
let x = 5;
let y = !x;
println!("{}", y);
The output of this code will be -6
.
Code explanation
let x = 5;
: This line declares a variablex
and assigns it the value5
.let y = !x;
: This line declares a variabley
and assigns it the value of the bitwise negation ofx
.println!("{}", y);
: This line prints the value ofy
to the console.
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...