I'm doing some bit twiddling and I'd like to print all the bits in my u16.
let flags = 0b0000000000101100u16;
println!("flags: {:#b}", flags);
This prints flags: 0b101100
.
How do I make it print flags: 0b0000000000101100
?
I'm doing some bit twiddling and I'd like to print all the bits in my u16.
let flags = 0b0000000000101100u16;
println!("flags: {:#b}", flags);
This prints flags: 0b101100
.
How do I make it print flags: 0b0000000000101100
?
The
018
pads with zeros to a width of 18. That width includes0b
(length=2) plus a u16 (length=16) so18 = 2 + 16
. It must come between#
andb
.Rust's fmt docs explain both leading zeros and radix formatting, but don't show how to combine them.
Here are u8, u16, and u32: