Possible Duplicate:
Why is modulo operator necessary?
I need help understanding how does &
give the modulus? I am working on an assignment to use memory access times to determine the cache sizes. Currently I am getting wierd results for the L3 size. I think it has something to do with &
only working well for powers of 2, or something like that? So I want to understand how it actually works
lengthMod = 1024/sizeof(int) - 1;
for (unsigned int k = 0; k < REPS; k++) {
data[(k * 16) & lengthMod]++;
}
Will &
always work? Or does it only work with some values? What actually happens for other values?