I wrote this to help me understand Abigail's code. I'd never seen the xor-string trick before.

#!perl use strict; use warnings; while (my $line=<DATA>) { chomp $line; my ($f, $s) = split /\s+/,$line; unless (length ($f) == length ($s)) { print "\"$line\" -> $f-$s\n"; next; } if ($f == $s) { print "\"$line\" -> $f\n"; next; } my $first = join ' ',map {sprintf("%08b",ord)} ("$f" =~ /./g); print "$f\t= $first\n"; my $second = join ' ',map {sprintf("%08b",ord)} ("$s" =~ /./g); print "$s\t= $second\n"; my $xor = join ' ',map {sprintf("%08b",ord)} (("$f" ^ "$s") =~ /./ +g); print "XOR\t= $xor\n"; my $index_of_first_diff = 0; $index_of_first_diff++ while($xor =~ /00000000 /g); print "Index\t= " , ' 'x9x$index_of_first_diff, "$index_of_first_d +iff\n"; print "Result\t= $f-", substr ($s, $index_of_first_diff), "\n\n"; } __DATA__ 324 329 325 349 340 509

Output -

d:\>test.pl 324 = 00110011 00110010 00110100 329 = 00110011 00110010 00111001 XOR = 00000000 00000000 00001101 Index = 2 Result = 324-9 325 = 00110011 00110010 00110101 349 = 00110011 00110100 00111001 XOR = 00000000 00000110 00001100 Index = 1 Result = 325-49 340 = 00110011 00110100 00110000 509 = 00110101 00110000 00111001 XOR = 00000110 00000100 00001001 Index = 0 Result = 340-509

In reply to Re: Re: Re: eliding number ranges by EdwardG
in thread eliding number ranges by qq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.