Representations of numbers are always big endian.

The OP said hex string, not hex number.

To elaborate, lets take the decimal number 1000.  Depending on whether it's stored big- or little-endian (in memory, in a file, etc.), you could find it as the (2-byte) string 03e8, or e803 (written in hex), and you could convert it to the number 1000 using any of the following (where 'n' and 'v' stand for "unsigned 16-bit in big-endian order" and "unsigned 16-bit in little-endian order" respectively):

print unpack('n', pack('H*', '03e8')), "\n"; # 1000 print unpack('v', reverse pack('H*', '03e8')), "\n"; # 1000 print unpack('v', pack('H*', 'e803')), "\n"; # 1000 print unpack('n', reverse pack('H*', 'e803')), "\n"; # 1000

Whereas the correct usage of 'n' or 'v' in combination with reverse does matter here, it doesn't when you have the symmetric hex string 'ffff'. Any combination will do (in particular, it's irrelevant whether you use the big- or little-endian unpack pattern):

print unpack('n', pack('H*', 'ffff')), "\n"; # 65535 print unpack('v', reverse pack('H*', 'ffff')), "\n"; # 65535 print unpack('v', pack('H*', 'ffff')), "\n"; # 65535 print unpack('n', reverse pack('H*', 'ffff')), "\n"; # 65535 print unpack('n', reverse pack('H*', 'ffff')), "\n"; # 65535 print unpack('v', pack('H*', 'ffff')), "\n"; # 65535 print unpack('v', reverse pack('H*', 'ffff')), "\n"; # 65535 print unpack('n', pack('H*', 'ffff')), "\n"; # 65535

(think of half of the 'ffff' as big-endian, and the other half as little-endian — as with 03e8/e803 above)


In reply to Re^5: -1 from hex ffffffffffffffff ? by almut
in thread -1 from hex ffffffffffffffff ? by Spooky

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.