blob: 915f769dd4d2d95cf731585a3ddc0053e4d8d098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/usr/bin/perl -w
use bytes;
$c = 0;
while(<>) {
next unless @bytes = (/0x([0-9a-fA-F]{2})/g);
for(@bytes) {
if(!($c % 8)) {
print " .byte ";
}
printf "\$%02X", (reverse_bits(hex $_) >> 1);
if(($c % 8 == 7) || ($c == $#bytes)) {
print "\n";
$c = 0;
} else {
print ",";
$c++;
}
}
}
sub reverse_bits {
my $bitstr = reverse sprintf("%08b", $_[0]);
return eval "0b$bitstr";
}
|