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 match the end of a line in a Rust regex?
- How to use regex with bytes in Rust?
- How to yield a thread in Rust?
- How to use regex to match a double quote in Rust?
- How to split a string by regex in Rust?
- Hashshet example in Rust
- How to ignore case in Rust regex?
- How to use an enum in a Rust HashMap?
- How to use backslash in regex in Rust?
- How to multiply matrices in Rust?
See more codes...