Commits

Palmer, 2E0EOL committed 6e02c85 Draft

First crack at doing the math

  • Participants
  • Parent commits 2f9683f
  • Branches develop

Comments (0)

Files changed (1)

 
 use constant PARAGRAPH_LENGTH => (16);
 
+sub HexToInt($) {
+	my $r;
+	my $h = shift;
+	my %hexMap = (
+		'a' => 10, 'b' => 11, 'c' => 12,
+		'd' => 13, 'e' => 14, 'f' => 15
+	);
+
+	die("Illegal digit - $h") if ( !defined($h) || $h !~ m/^[0-9a-f]$/ );
+	return $h if ( $h =~ m/^\d$/ ); # Simples
+	$r = $hexMap{$h};
+	die 'Assertion failure' unless ( $r =~ m/^\d{2}$/ && $r > 9 && $r < 16 );
+	return $r;
+}
+
 sub UnDump($) {
 	my $File = shift;
 	my $line = '';
 			printf("Offset: %s, data: %s\n", $offset, $data);
 			@split = split(m/\s+/, $data);
 			foreach my $octet_unchecked ( @split ) {
-				die sprintf('%c', $octet_unchecked);
+				my $octet_denary = 0;
+				my ( $l, $r );
+				next if ( $octet_unchecked !~ m/^[0-9a-f]{2}$/o ); # Skip invalid bytes
+				$l = substr($octet_unchecked, 0, 1);
+				$r = substr($octet_unchecked, 1, 1);
+				$octet_denary = 16 * HexToInt($l);
+				$octet_denary += HexToInt($r);
 			}
 		} else {
 			warn "Garbage on line";