Looking at the list of bitwise operators in the Rust Book, I don't see a NOT operator (like ~
in C). Is there no NOT operator in Rust?
Asked
Active
Viewed 2.9k times
1 Answers
76
The !
operator is implemented for many primitive types and it's equivalent to the ~
operator in C. See this example (playground):
let x = 0b10101010u8;
let y = !x;
println!("x: {:0>8b}", x);
println!("y: {:0>8b}", y);
Outputs:
x: 10101010 y: 01010101
See also:

Shepmaster
- 388,571
- 95
- 1,107
- 1,366

Lukas Kalbertodt
- 79,749
- 26
- 255
- 305
-
3For the record, now this can be found in the reference: https://doc.rust-lang.org/reference/expressions.html#negation-operators – jp48 Sep 08 '17 at 15:09
-
3Now at https://doc.rust-lang.org/reference/expressions/operator-expr.html#negation-operators – Craig McQueen Aug 25 '20 at 03:59