Skip to content

Instantly share code, notes, and snippets.

@zzeroo
Forked from anonymous/playground.rs
Created April 18, 2016 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzeroo/48a3bc9f99bb61ba3647467820e64b26 to your computer and use it in GitHub Desktop.
Save zzeroo/48a3bc9f99bb61ba3647467820e64b26 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