I’m trying loop over a set of bytes to convert them to a number. However, I get weird error where it complains about u6
not being convertable to i64
.
This code shows the same error:
const std = @import("std");
fn foo(input: []const u8) void {
var acc: i64 = 0;
for (0..4) |pow| {
acc += (@as(i64, @intCast(input[pow + 1]))) << std.math.pow(i64, 8, @as(i64, @intCast(pow)));
}
}
pub fn main() !void {
const input: []const u8 = "\xFF";
foo(input);
}
And the error on compiler explorer is this:
example.zig:6:68: error: expected type ‘u6’, found ‘i64’
example.zig:6:68: note: unsigned 6-bit int cannot represent all possible signed 64-bit values
Compiler returned: 1
I am very confused and would like some help understanding what’s going wrong. To me there is no problem casting these usize
s to i64
s and the u6
in the error message seems completely unrelated to the actual error.