BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
d496995
Branches
Tags
master
mips_sys
stuff
crc32.pl
perl scripts to convert packet data formats, some example packets
Stefan Schuermans
commited
d496995
at 2012-03-24 13:57:41
crc32.pl
Blame
History
Raw
#! /usr/bin/perl use strict; use warnings; # calculate CRC32 sub crc32 { my $bytes = shift; # array reference my @tab = ( 0x77073096, 0xEE0E612C, 0x076DC419, 0x0EDB8832, 0x1DB71064, 0x3B6E20C8, 0x76DC4190, 0xEDB88320 ); my $crc = 0xFFFFFFFF; for (my $i = 0; $i < @{$bytes}; ++$i) { my $val = $crc ^ @{$bytes}[$i]; $crc >>= 8; for (my $b = 0; $b < 8; ++$b) { if ($val & 1 << $b) { $crc ^= $tab[$b]; } } } $crc ^= 0xFFFFFFFF; $crc = [ $crc & 0xFF, $crc >> 8 & 0xFF, $crc >> 16 & 0xFF, $crc >> 24 & 0xFF ]; return $crc; # array reference } 1;