Created
April 18, 2016 10:31
-
-
Save anonymous/a155c7a45daf180da85fb820cd752b15 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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