Print numbers *right aligned* in columns as Bin, Hex and Oct

'''
for e in 1..12 {
println!("Bin {i:b}, Hex {i:X}, Oct {i:o}", i = e);
}
'''

You can use the > character to align to the right.

assert_eq!(format!("Hello {:>5}!", "x"),  "Hello     x!");

The std::fmt module docs have a section on fill and alignment.

3 Likes

thank you! it works...

println!("Bin {i:>10b}, Hex {i:>3X}, Oct {i:>3o}", i = e);

fixed the formatting above...

1 Like

The way to make a code block is to use the backtick character ` instead of the single quote character '

2 Likes