我有大量的块总是236个字节。然后我有一些条目需要安装到块中,这些条目有时不能完美地放入块中,因此块将留下几个空字节。数学,块和条目
我试图制定出位置来写的条目,哪块这应该英寸
int blocklen = 236;//always the same
int entryindex = 14;//example index of an entry to write
int entrylength = 16;//this will be the same in all entries in these blocks.
int blockindex = ((entryindex + 1) * entrylength)/blocklen;//this works and will correctly calculate the index of the block to write to.
int offset = ((entryindex) * entrylength) % blocklen;// this is incorrect, I need it to work out the offset with in the block.
如果我entryindex是13,将制定出如块0是@ 208,和那是对的。但是,如果它是14,它将不适合第一个块,所以它应该是块1 @ 0,而是它表示在偏移量224处的块1,并且224是第一个块中的偏移量,但是我需要将它移到下一个块。
反正数学不太好,这不是我的一天,所以我只是想知道你们中的任何一位能否帮助我完成这一行代码。
你为什么要纪念这个问题,C和C#? – 2013-02-19 14:03:26
我在想C和C#编码器都可以帮我修复它。对不起,如果这是错的。 – godzcheater 2013-02-19 14:09:56
如果语言不相关,我建议使用伪代码并要求伪代码答案。 C和C#非常不同,会造成混淆。 – 2013-02-19 14:14:19