std-method

Integer rotate_left and rotate_right

Move bits around a fixed-width word, putting bits leaving one end back at the other. Expected stdout (not executed): 00000111 11000001 Common mistake: Using a normal shift when rotation is required.

Formal Syntax & Structure

rust syntaxrust
x.rotate_left(bits); x.rotate_right(bits)

Working Example

Example Snippetrust
fn main() {    let flags = 0b1000_0011u8;    println!("{:08b} {:08b}", flags.rotate_left(1), flags.rotate_right(1));}
Rust Reference