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 use regex to match a double quote in Rust?
- How to create a HashMap of structs in Rust?
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to modify an existing entry in a Rust HashMap?
- How do I identify unused variables in Rust?
- How to use negation in Rust regex?
- Regex example to match multiline string in Rust?
- How to use a Rust HashMap in a struct?
- How do I use a variable number of arguments in Rust?
See more codes...