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?
The bitwise NOT operator in C++ is the tilde character ~ . Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0.
var = expr , ident = type. Assignment/equivalence. == expr == expr. Equality comparison.
Bitshifting shifts the binary representation of each pixel to the left or to the right by a pre-defined number of positions. Shifting a binary number by one bit is equivalent to multiplying (when shifting to the left) or dividing (when shifting to the right) the number by 2.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With