Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Unpack 64 bit value

by Marshall (Abbot)
on Sep 10, 2009 at 08:41 UTC ( #794511=note: print w/replies, xml ) Need Help??

in reply to Unpack 64 bit value

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.

Replies are listed 'Best First'.
Re^2: Unpack 64 bit value
by DrHyde (Prior) on Sep 10, 2009 at 11:04 UTC
    This is just *so* wrong. Endianness is irrelevant to whether q is a valid format.
      I don't have access to a 64 bit platform.. "Endianness" is always relevant as there is fundamental difference between say how Intel and say Motorola machines work.

      This goes to the hardware level about how data is actually stored in sequential memory locations and is enforced by the hardware. If I do a binary byte dump to disk, of say array of 32 bit values on a VAX or Intel platform, nothing is gonna change the fact that this same array will look different on the disk from a binary byte dump from a Motorola platform.

        The OP indicates that he is getting a syntax/compile-time error. Endianness doesn't matter at that point, which is what DrHyde indicated. And the likely explanation for the error is provided by almut in 794510.

        Elda Taluta; Sarks Sark; Ark Arks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794511]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-05-28 10:11 GMT
Find Nodes?
    Voting Booth?