std-method
Integer wrapping_shl and wrapping_shr
Reduce the shift count modulo the type width. Unlike rotations, shifted-out bits disappear. Expected stdout (not executed): 6 64 Common mistake: Confusing wrapping shifts with rotating bits around the byte.
Formal Syntax & Structure
rust syntaxrust
x.wrapping_shl(bits); x.wrapping_shr(bits)Working Example
Example Snippetrust
fn main() { println!("{} {}", 3u8.wrapping_shl(9), 128u8.wrapping_shr(9));}