Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Update: this post is obviously not clear...I am not familiar with 64 bit ASM, so I will defer to folks who claim that knowledge.

Update: I guess I am having a "bad hair day"...Obviously this post is not clear. Sorry about that. The general idea is correct. In the Intel bit world, reading bytes 1,2,3,4 (for 32 bit integer) from a disk file means byte order 3,4,1,2 in memory. I know that's goofy and I have no defense! This is "unpack" with V4 format. I think Motorola is something like N4 format (1,2,3,4). If you understand this part, everything below may make sense.

This (Unpack) will be platform specific. There is a difference between what is called "little Endian" and "big Endian". Here is a wiki article on this: The basic thing is whether most significant byte or word appears first or second in the sequence.

It is absolutely crucial that you understand binary representations and how to convert a linear set of bytes in a file to "endianness" for your machine.

Update: If 32 bit (4 byte order) doesn't matter then certainly 64 bit (8 byte order) won't either. If so, skip the rest of this post. If you are going to process an array in binary format in 'C' or other languages, or dump a Perl binary structure, this post is direct to the point.

Normally 32 bits is enough for a 64 bit integer value conversion because the most significant 4 bytes are all zero's (positive number) or all one's (negative number, sign bit extension). A Perl float can handle something like 53 bits.

There is likely to be "big" problems if you have an int that cannot be represented in 32 bits. That would mean that you can't easily pass this value as a simple int to other Perl subs, etc.

So basically if upper 32 bits are all zero's or all one's, it doesn't matter. If that is not true, then you have "big int" problems.

I guess we get into the case of an "unsigned" 32 bit int where the most significant bit is 1. In that case the upper 32 bits would also be zero and this is a specific case of something that can't be represented as 32 signed bits.

In reply to Re: Unpack 64 bit value by Marshall
in thread Unpack 64 bit value by nagalenoj

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (6)
    As of 2018-06-19 13:37 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (114 votes). Check out past polls.