On 7 Jan 2006 at 13:51, Gert Doering wrote:
Hi,
On Sat, Jan 07, 2006 at 12:12:05PM -0000, Prof A Olowofoyeku (The African Chief) wrote: > Which I have half-translated into this: > for (; length; length + (length shr 8)) do > crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; > > As you can see, I don't understand the for-loop ...
for() loops in C are actually best translated into while loops first:
for( start; condition; increment ) { block; }
translates to:
start; while( condition ) { block; increment; }
so in this case, the C statement
for(; length; length >>= 8) crc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];
can be translated to:
/* no loop initialization */ while( length != 0 ) { crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; length := length shr 8; }
("variable >>= bits" is the same as "variable = variable >> bits")
Many thanks. This was the information and confirmation that I needed.
I had alread translated it to: While (length > 0) do begin crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; length := length shr 8; end;
but I was not sure what I was doing!
From what you say, it would seem that this is more correct for the loop
condition (if "length" is signed): While (length <> 0) ...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/