Fix crc32 code warning
This commit is contained in:
+13
-13
@@ -15,19 +15,19 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
uint32_t crc32(const char *s,size_t n, uint32_t crc=0xFFFFFFFF) {
|
||||
|
||||
for(size_t i=0;i<n;i++) {
|
||||
char ch=s[i];
|
||||
for(size_t j=0;j<8;j++) {
|
||||
uint32_t b=(ch^crc)&1;
|
||||
crc>>=1;
|
||||
if(b) crc=crc^0xEDB88320;
|
||||
ch>>=1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
uint32_t crc32(const char *s, size_t n, uint32_t crc = 0xFFFFFFFF) {
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
unsigned char ch = static_cast<unsigned char>(s[i]);
|
||||
for (size_t j = 0; j < 8; j++) {
|
||||
uint32_t b = (ch ^ crc) & 1;
|
||||
crc >>= 1;
|
||||
if (b) crc = crc ^ 0xEDB88320;
|
||||
ch >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
Reference in New Issue
Block a user