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
- Regex example to match multiline string in Rust?
- How to use binary regex in Rust?
- How to match the end of a line in a Rust regex?
- How to use regex captures in Rust?
- How to use regex to match a group in Rust?
- How to perform matrix operations in Rust?
- How to match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to make regex case insensitive in Rust?
- How to print a Rust HashMap?
See more codes...