Not inverting i_1, i_2, i_3
Correct result:
function test()
for i_1 = 0:1
for i_2 = 0:1
for i_3 = 0:1
n = i_3*2^0 + i_2*2^1 + i_1*2^2
println("$(i_1)$(i_2)$(i_3) => $n")
end
end
end
end
test()
000 => 0
001 => 1
010 => 2
011 => 3
100 => 4
101 => 5
110 => 6
111 => 7
Result still with i_1, i_2, i_3 inverted
function test2(v::Val{N}) where {N}
p2 = reverse(ntuple(i->2^(i-1), v))
for idx in CartesianIndices(ntuple(i->0:1, v))
n = sum(reverse(Tuple(idx)) .* p2)
println("$(idx) = > $n")
end
end
test2(Val(3))
CartesianIndex(0, 0, 0) = > 0
CartesianIndex(1, 0, 0) = > 1
CartesianIndex(0, 1, 0) = > 2
CartesianIndex(1, 1, 0) = > 3
CartesianIndex(0, 0, 1) = > 4
CartesianIndex(1, 0, 1) = > 5
CartesianIndex(0, 1, 1) = > 6
CartesianIndex(1, 1, 1) = > 7