2009. augusztus 14., péntek

Intel HEX formátum

Itt van egy kis példa program : (hogy mire jó és mi értelme van, azt majd később leírom (talán)

my $databyte = "00";
my $checksum = "00";
my $address = "0000";

while ($line = <stdin> ) {

chomp($line);
$line =~ s/ //g;
$address = sprintf("%04X",hex($address) + hex($databyte));
$databyte = sprintf("%02X",length($line)/2);
$begstr = "$databyte" . "$address" . "00" . "$line";
$checksum = checksum($begstr);
$outstr = "$begstr" . "$checksum";
print ":$outstr\n";

}

print ":00000001FF";
exit;

sub checksum {

my $a = shift;

my $len = length($a)/2;
my $count = 0;

for($i = 0; $i < $len; $i++) {
my $ax = substr($a,$i*2,2);
$count = $count + hex($ax);
}
my $hcount = sprintf("%02X",$count);

my $b = ~ hex(substr($hcount, length($hcount)-2,2));
$b = $b - 4294967039;
my $c = sprintf("%02X",$b);
if(length($c) > 2) { return substr($c,length($c)-2,2) }

return $c;

}

1 megjegyzés:

  1. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you must watch this video
    right away...

    (VIDEO) Text Your Ex Back?

    VálaszTörlés