As I understand the OP...

The two byte binary data sequence 45d2 (specificaly qq{\x45\xd2}) would unpack with the 'v' specifier as the hex number 0xD245.

>perl -wMstrict -le "my $bin = qq{\x45\xd2}; printf qq{0x%04X \n}, unpack 'v', $bin; " 0xD245

With the first code example of the OP, the eight byte binary data sequence 45d2ff76893a0033 (or qq{\x45\xd2\xff\x76\x89\x3a\x00\x33}) would unpack as
0xD245 0x76FF 0x3A89 0x3300.

>perl -wMstrict -le "my $bin = qq{\x45\xd2\xff\x76\x89\x3a\x00\x33}; my @data = unpack 'v4', $bin; printf '0x%04X ', $_ for @data; " 0xD245 0x76FF 0x3A89 0x3300

But as I understand it, amigero wants 0x76FF 0xD245 0x3300 0x3A89.

>perl -wMstrict -le "my $bin = qq{\x45\xd2\xff\x76\x89\x3a\x00\x33}; my @data = map reverse(unpack 'v*'), unpack '(a4)*', $bin; printf '0x%04X ', $_ for @data; " 0x76FF 0xD245 0x3300 0x3A89

It's a one-liner, but as far as 'efficiency' goes, the remarks of others are pertinent.


In reply to Re: Word reverse by AnomalousMonk
in thread Word reverse by amigero

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.