1

I need to calculate how many transactions are required to transmit n bytes. I can only read b bytes from the external hardware in a single transaction. The number of transactions is N. This pseudo-code seems sufficient:

If n=0 then
  N=0 // 0 transactions needed as no data has to be transferred IN or OUT
else
  if n%b then
    N=n/b+1 // n is not wholly divisible by b, thus the (last) Nth transaction shall transfer less than b bytes
  else
    N=n/b // all N transactions shall transfer exactly b bytes
  end if
end if

My question is simply, is there a more compact way to do this? I am checking using modulus operator that n%b is nonzero since if I have to transfer 3 bytes and the buffer is 8 bytes, then 3/8 shall be 0 in int but the +1 shall take care of it giving 1 transaction.

quantum231
  • 2,420
  • 3
  • 31
  • 53

0 Answers0