views:

33

answers:

1

I've used unpack to convert most of the data types I have in a binary file that I'm parsing with little problems. I have no idea how to work with a big endian 64-bit signed long. I think this data type is stored using 2's complement. The application of the data file I'm reading is a java app so I assume it's 2's complement. I don't need to work with it as a number but simply work with it as a string.

A: 

Java 64-bit integers are indeed stored natively as "network-order" (big endian, i.e. start with the most significant byte) 8-byte 2's complement format. So typically you take byte at a time, shift left by 8, repeat. Byte values can be thought of as unsigned (while result is signed), but with left-shifting this should not matter. So: first you just created equivalent 64-bit int from bytes, and display from there. No point in using short cuts; while it is possible, you just end up with more complicated and less efficient code.

StaxMan
I guess I forgot to mention that the PHP I'm working with is 32-bit. I guess I need to try working with the BCMath library or some such?
fadeddata
I don't think 32-bitness matters in this case, it should not affect existence of 'bigger' datatypes (rather matters with addressing etc). But I am bit of PHP newbie so I hope others can confirm this.
StaxMan