in reply to Nibble swap

Why do any string conversions here at all? my $swapped = ($_ << 4 | $_ >> 4) & 0xFF;

Makeshifts last the longest.

Replies are listed 'Best First'.
Re2: Nibble swap
by blakem (Monsignor) on Oct 04, 2002 at 20:45 UTC
    That would be great if << and >> worked on bits, but I don't think they do.
    % perl -le 'print "5" << 4' 80
    i.e. 5*2^4 == 80

    -Blake

      Doh, you're right. But
      $ perl -le 'print ord("5") << 4' 848
      Though I'm not sure we can just say my $swapped = (ord($_) << 4 | ord($_) >> 4) & 0xFF; to fix it. (Don't seem to be able to wrap my head around it right now.)

      Makeshifts last the longest.