I am looking to create a macro that will display a type of number in hex along leading zeros equal to its size. For example, hex!(2u8)
will print $02
(leading zero) and hex!(2u16)
will print $0002
(16bit leading zeros)
This is what I have now, but it only works for 8bit numbers. It will display numbers larger than 8bit, but it won't display leading zeros equal to the size. I need a way to substitute the size of the integer in for 2
in ${:02X}
but the print!()
macro requires a string literal.
macro_rules! hex {
($val:expr) => {{
println!("${:02X}", $val);
}}
}