#convert []u64 to []u8
1 messages · Page 1 of 1 (latest)
i basically want to just cast the pointer
and multiply the length by 8 since the elements are 8 times smaller
i have an idea let me just check if it actualy works
you want sliceAsBytes, asBytes is for single items
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
also mlugg is working on implementing this in ptrCast so it'll just work soon probably
i was thinking on the lines of memcopy
allocate the u8 slice and memcopy the u64 slice into it
no need; as mentioned, this works:
const slice_of_u64: []const u64 = &[_]u64{ 0, 1, 2, 3, 4 };
const slice_of_u8 = std.mem.sliceAsBytes(slice_of_u64);