At 09:50 AM 3/19/2002 -0500, Tim Musson wrote:
>Thanks to all who sent pointers!
>
>Here is my code before I put it up as a web page tool (and clean it up
>and comment it <g>).
>
>comments/suggestions anyone?
>
>#!perl -w
>use strict;
>use diagnostics;
>
>my $debug = "yes";
>my (@mac);
>my $mac = "0123 6789 cdef";
>$mac =~ s/\s//g;
>my $i = 0;
>while($mac =~ /(.{2})/g){
>         $mac[$i++] = $1;
>         my $str = unpack("B8", pack("H2", $1));
>         print $1 . " - " . "$str\n" if $debug;
>         my $revstring = reverse($str);
>         my $hex2 = unpack("H2", pack("B8", $revstring));
>         print "     $revstring - $hex2\n\n" if $debug;
>}

I found a slightly more concise phrase. The first transformation swaps the 
two hex digits within each byte, keeping the bytes in original order. The 
second transformation is a lookup table for the function that reverses any 
one hex digit.

         my $Debug = 1;
         my $InputStr = '7BB57DF7';

         (my $NibbleSwapped = $InputStr . ' ') =~ s/(.)(.)/$2$1/g;
         (my $Reverse = $NibbleSwapped) =~ tr/0-9A-F/084C2A6E195D3B7F/;

         print $InputStr . "- " .
             $NibbleSwapped . "-" .
             $Reverse . "\n" if $Debug;

Obviously, this doesn't strips spaces etc - that's easy enough. I just 
started the camel book a few days ago, so I hope the cognoscenti can point 
out improvements.

-- tvc


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to