I am trying to use a ring buffer to store data. I am using an array of 56 bytes and each item of data is 8 bytes long. The following codes work
for j=0 to 7:
buffer[i+j] = newData[j]
i = (i+8) % 56
But when I changed it to 9 bytes long
for j=0 to 8:
buffer[i+j] = newData[j]
i = (i+9) % 56
it produces nonsense. I am pretty sure it’s the modular arithmetic’s problem but I am not sure why. Can someone explain the logic to me, thanks.
for j=0 to 7:
buffer[i+j] = newData[j]
i = (i+8) % 56
But when I changed it to 9 bytes long
for j=0 to 8:
buffer[i+j] = newData[j]
i = (i+9) % 56
it produces nonsense. I am pretty sure it’s the modular arithmetic’s problem but I am not sure why. Can someone explain the logic to me, thanks.