是否有更紧凑的方法来计算所需的交易数量?

时间:2017-02-15 23:44:56

标签: c++ c algorithm

我需要计算传输n个字节所需的事务数。我只能在单个事务中从外部硬件读取b个字节。事务的数量是N.这个伪代码似乎就足够了:

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

我的问题很简单,是否有更紧凑的方法来做到这一点?我正在使用模数运算符检查n%b是非零的,因为如果我必须传输3个字节并且缓冲区是8个字节,那么3/8在int中应该是0但是+1应该处理它给出1个事务。 / p>

0 个答案:

没有答案
相关问题