Skip to content

Instantly share code, notes, and snippets.

@ilopX
Created April 29, 2023 11:57
Show Gist options
  • Save ilopX/bdb8118f5f0d99f66f5575da32abd22b to your computer and use it in GitHub Desktop.
Save ilopX/bdb8118f5f0d99f66f5575da32abd22b to your computer and use it in GitHub Desktop.
macro_rules! print_mem {
($ptr:expr, $address:expr) => {
unsafe {
let a_ptr: *const u32 = &$ptr;
let b_ptr: *const u8 = a_ptr as *const u8;
println!("{:#0x}", *b_ptr.offset($address));
}
};
}
fn main() {
let i: u32 = 0b10000000_11000000_11100000_11110000;
println!("{:#0x}", i);
print_mem!(i, 0);
print_mem!(i, 1);
print_mem!(i, 2);
print_mem!(i, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment