Created
February 16, 2017 21:05
-
-
Save jdmichaud/c1f908c0e1e0251c3be0382d02c9ed1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fn main() { | |
let i: u64 = 0xDEADBEEFCAFEBABE; | |
let b1: u8 = ( i & 0x00000000000000FF) as u8; | |
let b2: u8 = ((i >> 8) & 0x00000000000000FF) as u8; | |
let b3: u8 = ((i >> 16) & 0x00000000000000FF) as u8; | |
let b4: u8 = ((i >> 24) & 0x00000000000000FF) as u8; | |
let b5: u8 = ((i >> 32) & 0x00000000000000FF) as u8; | |
let b6: u8 = ((i >> 40) & 0x00000000000000FF) as u8; | |
let b7: u8 = ((i >> 48) & 0x00000000000000FF) as u8; | |
let b8: u8 = ((i >> 56) & 0x00000000000000FF) as u8; | |
println!("b1 {}", format!("{:x}", b1)); | |
println!("b2 {}", format!("{:x}", b2)); | |
println!("b3 {}", format!("{:x}", b3)); | |
println!("b4 {}", format!("{:x}", b4)); | |
println!("b5 {}", format!("{:x}", b5)); | |
println!("b6 {}", format!("{:x}", b6)); | |
println!("b7 {}", format!("{:x}", b7)); | |
println!("b8 {}", format!("{:x}", b8)); | |
} |
DE AD BE EF DE AD BE EF
address 0 DE <---^ | | | | | | ^---> EF address 0
address 1 AD <------ | | | | ------> BE address 1
address 2 BE <--------- | | ---------> AD address 2
address 3 EF <------------ ------------> DE address 3
Big-Endian Little-Endian
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output on x86: