When formatting integer types to hexadecimal strings, I cannot get it to pad the numbers with zeroes:
println!("{:#4x}", 0x0001 as u16) // => "0x1", but expected "0x0001"
println!("{:#02x}", 0x0001 as u16) // => "0x1", same
Keep in mind that the leading 0x
is counted in the length so if you want something printed as 0x0001
then the length is really going to be 6, not 4.
fn main() {
println!("{:#06x}", 0x0001u16);
}
This prints 0x0001
as you wanted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With