summaryrefslogtreecommitdiffstats
path: root/data/crc7.pl
blob: 6d2734ef7938522cb568dcf77eff670a21135798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl

use bytes;

$c = 0;
foreach $b (@ARGV) {
    $b = hex($b);

    for ($i = 7; $i >= 0; $i--) {
	$x = ($b >> $i) & 1;

	$x ^= ($c & 0x40) >> 6;
	$c = ($c & 0x3f) << 1;
	$c ^= ($x ? 0x09 : 0x00);
    }
}

printf "%02x\n", ($c << 1) | 0x01;