#packed enum to u8 bytes?

1 messages · Page 1 of 1 (latest)

pine crane
#

use @bitcast instead of @intFromEnum

green marten
#

I cant get bitcast to work at all in an append() context.

pine crane
#

is out an arraylist of u8s?
in that case why not just do try out.append(@truncate(@bitCast(self.parsing)))?
the & 0xFF is probably screwing up the result type and @truncate will already mask it for you

green marten
#

Because I need all four u8's

#

Oh, so like htis

green marten
#

Wow, well this is unexpected:

#

OMG, so this doesnt work either:

#

Nor does this:

#

Maybe an inline function is needed to mash out a u32 into u8's for an array.... hmmm...

#

omg, this doesnt work either

var b: u8 = @as(u8, @bitCast(self.uid));
#
src/form.zig:66:25: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'u32' has 32 bits
    var b: u8 = @as(u8, @bitCast(self.uid));
#

Nor does this:

#

Maybe @bitcast is not the answer for getting a u32 into u8's

pine crane
#

I guess you'd do @truncate(@as(u32, @bitCast(self.parsing)))

#

Which makes sense ig truncate doesn't provide a result type

green marten
#

Thans, I finally worked it out after a lot of trial and error, heres how: