Processing blocks of bytes.

This is my first post so before I move on to the relevant matter, I'd like to say "Hello World" to everyone!

Now, on to business. As the title says I am attempting to process blocks of bytes (for this post we'll assume 128 bytes) in a buffer array using a loop. The purpose is general experimentation with message digest functions. So, let's say that the buffer is some arbitrary size rounded to the nearest multiple of 128 (with <128 blocks of information being padded with 0's to 128). Now my goal is to process 128 bytes and then move on to the next 128 bytes. I've been at it for about 16 hours total spread over the last 2 days and the solution seems to escape me. I understand that it can be achieved with a loop, but the configuration of the loop is my problem. My first attempt was:

1
2
3
4
5
6
7
8
9
while(blockCount > 0)
{
	for(int j=index;j<index+128;j++)
	{
		Block(buffer[j], checksum);
                index + 128;
	};
	blockCount =- 1;
}


Now, obviously it failed pretty badly because it only processed every 128th byte in the buffer, but I figured I was on the right track. The index is the index of the buffer array, with blockCount being the number of 128 byte blocks in the buffer. As you go through the loop it decrements the block by 1 every time it goes through until it reaches 0. The Block() function is the function which does the transformations on the blocks to output a checksum of the file.

What am I doing wrong and how can I fix it? Thanks.

closed account (zwA4jE8b)
blockCount -= 1;
not
blockCount =- 1;

=-1 sets blockCount to negative 1
closed account (zwA4jE8b)
same with the other operators, you need the arithmetic operator pre assignment operator.

1
2
3
4
5
int a = 5; //a == 5
a -= 3;     //a == 2
a *=2;     //a == 4
a /= 2;    //a == 2
a += 10; //a ==12 
Last edited on
Thanks guys!

I've actually realized a mistake while trying to accomplish what I'm setting out to do. I read an entire file into an accordingly sized buffer array and tried to break it into blocks to be read into a smaller fixed-sized array (128). What didn't occur to me is that it would be far, far easier to read the file in 128 byte blocks into a fixed sized array to do the operations, keeping the buffer and checksum array's compatible in size.

Thanks again.
Topic archived. No new replies allowed.