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 variablexand assigns it the value5.let y = !x;: This line declares a variableyand assigns it the value of the bitwise negation ofx.println!("{}", y);: This line prints the value ofyto the console.
Helpful links
Related
More of Rust
- How to match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to match a URL with a regex in Rust?
- How to get a capture group using Rust regex?
- How to create a Rust HashMap from a vec?
- How to replace all matches using Rust regex?
- How to split a string with Rust regex?
- How to get struct length in Rust
- How to replace strings using Rust regex?
- How to use non-capturing groups in Rust regex?
See more codes...