#convert []u64 to []u8

1 messages · Page 1 of 1 (latest)

barren summit
#

Given a slice of []u64 (of length 32), how can I convert it to a slice of []u8 of length 32 * 8. When I use asBytes, it just returns something of length 8 which is not what I want (probably the bytes of the pointer).

#

i basically want to just cast the pointer

#

and multiply the length by 8 since the elements are 8 times smaller

quasi flame
#

i have an idea let me just check if it actualy works

normal copper
#

you want sliceAsBytes, asBytes is for single items

barren summit
#

i mean i did this ```zig
const rs = result.mins[band * r .. (band + 1) * r];
print("{d}\n", .{rs.len});
var new_slice: []u8 = undefined;
new_slice.ptr = @ptrCast(rs.ptr);
new_slice.len = rs.len * 8; // * 8 because we are going from u64 -> u8
print("{d}\n", .{new_slice});

#

ahh

normal copper
#

also mlugg is working on implementing this in ptrCast so it'll just work soon probably

quasi flame
wraith nest