I'm trying to figure out what's going on here. I was under the impression that in the following program, the last field would contain the value 6 since it aligns with the lower 6 bits of the byte, but that doesn't seem to be the case.
const std = @import("std");
const mem = std.mem;
const debug = std.debug;
pub fn main() !void {
const num: u8 = 6;
const small = @bitCast(Small, num);
debug.print("\nfirst: {b}, last: {b}\n", .{ small.first, small.last });
debug.print("num: {b}\n", .{ num });
debug.print("small: {b}\n", .{ mem.toBytes(small)[0] });
}
pub const Small = packed struct {
first: u2,
last: u6,
};
first: 10, last: 1
num: 110
small: 110