Skip to content

Commit

Permalink
Fix crc32 code warning
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Apr 15, 2023
1 parent c5de72c commit 3aae416
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions examples/Crc32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3aae416

Please sign in to comment.