test "thing" {
const x: packed struct {
x: u4, y:u4,
} = .{.x = 0xf, .y = 0xe};
print("{x}\n", .{std.mem.asBytes(&x)});
}
So this piece of code should give me { fe }
as an output since we are supposed to control the bit order in packed structs right ?
But I get { ef }
instead.
Can someone explain to me why this happens ? I’ve only tested u4s, so I don’t know if it happens with other sizes, but why does this reversing happen at all ?
I don’t think it’s because of endianess. I’m on a little endian system, and doing the same thing with a packed struct with u8s is fine, the order is maintained.