I need just a little bit of help translating C to python. I have not used c++ in about 4 years now, and when I used it, I only new the basics. the context of this snippet is reading a file and creating a checksum
int ff7_checksum( void* qw )
{
int i = 0, t, d;
long r = 0xFFFF, len = 4336;
long pbit = 0x8000;
char* b=(char*)qw;
while( len-- ) {
t = b[i++];
r ^= t << 8;
for(d=0;d<8;d++) {
if( r & pbit )
r = ( r << 1 ) ^ 0x1021;
else
r <<= 1;
}
r &= ( 1 << 16 ) - 1;
}
return (r^0xFFFF)&0xFFFF;
}
I assume that
qwpoints at a buffer with a known size (4336) and that does not really represent a string (i.e. it might contain\0characters that should still be processed).However, in Python (2.x), we still generally model this as a string, since the string may contain embedded
\0bytes, and knows its own length. There is thus also no reason to hard-code the length.More idiomatically, we get something like: