|Just another Perl shrine|
Re: Unpack 64 bit valueby Marshall (Monsignor)
|on Sep 10, 2009 at 08:41 UTC||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.
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: http://en.wikipedia.org/wiki/Endianness. 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.