Hey.

Somebody'd asked for Reverse od script (which a smarter monger than I did 
as:
od -o <ascii.txt> | perl -ne 'split;shift @_;foreach (@_) {print 
pack("S",oct)}'
) as octal/binary math is not my strong point what I came up w/ is this, 
which seems to work:
#!/usr/bin/perl
while (<>) {
  @oct = split;
  $line = shift @oct;
  foreach ( @oct ) {
    $top = oct($_);
    $top_val = $top >> 8;   # shift it over to just have the top byte
    $bot = ($top - ( $top & ($top_val<<8) ) );  # beats me??
    $line .= sprintf(" %c %c ", $bot, $top_val );
  }
  print $line . "\n";
}

 #   echo "hey man\n what's up" | od -o | rod.pl
0000000 h e  y    m a  n
    w  h a  t '  s
0000020 u p

0000023

#   echo "hey man\n what's up" | od -o
0000000 062550 020171 060555 005156 073440 060550 023564 020163
0000020 070165 000012
0000023

but I'm really not clear as to why.  See the 'beats me' line - a blind 
squirrel sort of result of applying various bitwise ops using a 
cargo-cultish understanding of binary etc.

a

Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED]    VOICE: (608) 264-5178 ex 5738, FAX 
264-510

  Disclaimer: [see: http://www.goldmark.org/jeff/stupid-disclaimers/ ]


Reply via email to