operator
Rust >>: shift bits right
Unsigned right shift fills upper bits with zeros. Signed right shift propagates the sign bit. Expected output (not executed): 00101000 -4 Why: The unsigned value shifts down; the negative signed value retains its sign. Common mistake: Right shift on negative signed values is not always the same as division by a power of two, which truncates toward zero. Advanced connection: `std::ops::Shr`; `ShrAssign` for `>>=`.
Formal Syntax & Structure
rust syntaxrust
a >> nWorking Example
Example Snippetrust
fn main() { let unsigned = 0b1010_0000_u8; println!("{:08b}", unsigned >> 2); println!("{}", -7_i8 >> 1);}