Re: signed int64 pack/unpack [message #184579 is a reply to message #184577] |
Sun, 12 January 2014 02:42 |
Ben Bacarisse
Messages: 82 Registered: November 2013
Karma:
|
Member |
|
|
cameron7(at)gmail(dot)com writes:
> I'm having a bit of trouble figuring out a straightforward way to
> "pack" / "unpack" a signed int64.
>
> I'm on a 64-bit machine, but the 'i' and 'I' are coming back with
> 4-byte length.
There is no explicit format for 64-bit ints. The i/I formats are used
for a native "int" but that need not be 64 bits on a 64-bit machine.
The function is borrowed from Perl whose documentation says a bit more
This 'integer' is _at_least_ 32 bits wide. Its exact size depends on
what a local C compiler calls 'int'.
On my 64-bit Linux machine, 'int' is 32 bits.
> And of course even though double comes back with 8
> length it's a floating point and thus loses precision.
>
> Any thoughts? Any help would be greatly appreciated.
You could, perhaps, just pack the two halves. Of course doing it
yourself rather defeats the purpose, but I am not sure there is another
way.
Depending on what you need this for, you could consider another format
altogether (ASCII, for example).
> BTW, unsigned int64 seems relatively straightforward, but signed int64
> has been unusually difficult to figure out.
How are you doing unsigned 64-bit ints?
--
Ben.
|
|
|