#Formatting numbers with hexadecimal in varying endianess

1 messages · Page 1 of 1 (latest)

balmy gust
#

Whenever I run the following code on my (little-endian) machine, it prints the number in big-endian format.rs std.debug.print("{x:0>4}", .{ 22222 });Is there a way I can make this format in the native endian using std.fmt or do I have to rely on conditions and do it manually?

gritty hollow
#

you could use std.mem.nativeToLittle to force the number to be little-endian or @bitCast to reinterpret it as a byte array (which will account for host endianness)

#

std.fmt prints most significant digit first (which is not quite the same as endianness) since that's how humans tend to write numbers