#How to print a hex number with padded zeros?

1 messages · Page 1 of 1 (latest)

north totem
#

Say I have the numbers 0x00FF and 0xFFEF, if I print them to the terminal with std.debug.print, I get:

ff
ffef

Is there a convenient way to get the first number to print with 2 prefixed zeros? like 00ff?

#

How to print a hex number with padded zeros?

echo wasp
#

You can check the std/fmt.zig file to see the options on how to format.
For printing, the string is "{x:0>4}" (Hexadecimal, pad with 0s, right align 4)