Board index » cppbuilder » bit shifting problem
leeaids
![]() CBuilder Developer |
bit shifting problem2005-10-21 10:27:09 AM cppbuilder41 Hi, i'm trying to port a code in linux c. the code creates a checksum for a file through bit shifting. but when i port the code to borland c builder(windows 2k) the calculated checksum is different than the one calculated in linux. is there any difference in the bitshifting done by linux and borland c builder for windows? thanks here is the code: int cs_calc_sum(FILE *fp, unsigned long *res, int tagged) { unsigned char buf[BUFLEN]; unsigned long crc = 0L; uintmax_t length = 0; size_t bytes_read; fseek(fp, 0, SEEK_SET); while((bytes_read = fread(buf, 1, BUFLEN, fp))>0) { unsigned char *cp = buf; if(length + bytes_read < length) return 0; if(bytes_read != BUFLEN && tagged) bytes_read -= 8; length += bytes_read; while(bytes_read--) crc =(crc << 8) ^ crctab[((crc>>24) ^ *cp++) & 0xFF]; } if(ferror(fp)) return 0; for(; length; length>>= 8) crc =(crc << 8) ^ crctab[((crc>>24) ^ length) & 0xFF]; crc = ~crc & 0xFFFFFFFF; *res = crc; } |