Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2016 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a155c7a45daf180da85fb820cd752b15 to your computer and use it in GitHub Desktop.
Save anonymous/a155c7a45daf180da85fb820cd752b15 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#[derive(Debug,PartialEq)]
enum Bitorder {
LSBFIRST,
MSBFIRST,
}
fn main() {
let order: Bitorder = Bitorder::LSBFIRST;
if order == Bitorder::MSBFIRST {
println!("MSBFIRST");
let data: u32 = 0b10001111;
for i in 0..8 {
match (data >> i) & 1 {
1 => println!("{} true", i+1),
_ => println!("{} false", i+1),
}
}
} else {
println!("LSBFIRST");
let data: u32 = 0b10001111;
for i in (0..8).rev() {
match (data >> i) & 1 {
1 => println!("{} true", i+1),
_ => println!("{} false", i+1),
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment