in reply to -1 from hex ffffffffffffffff ?

$ perl -e"print unpack('q',pack('H*', 'ffffffffffffffff'))" -1

See pack  (and Two's complement for background).

(The 'q' stands for a 64-bit value, but you'd also get -1 for any other signed int of shorter length, such as 'l' (32-bit), 's' (16-bit), 'c' (8-bit) — in which case only part of the bit pattern would be used in the unpack...)

Replies are listed 'Best First'.
Re^2: -1 from hex ffffffffffffffff ?
by ikegami (Patriarch) on Oct 02, 2009 at 16:59 UTC

    That should be q> (big-endian byte order), not q (native byte order).

    Furthermore, it would be better to pad out the hex number in case fewer than 16 digits are provided.

    sub hex_to_signed_quad { return unpack 'q>', substr(('0'x16).$_[0], -16); }
      should be q> (big-endian byte order)

      Well, no one said in what order the ffffffffffffffff is to be interpreted, and in this special case of all bits being ones, it wouldn't make much of a difference anyway :)

        Representations of numbers are always big endian. The sole case to have little endian numbers I can remember encountering used giant red flags to avoid confusion since representation of numbers are always big endian.

        Update: I suppose the first statement may not apply where non-latin scripts are involved. (I bet the most significant digit is placed first in all languages.)

Re^2: -1 from hex ffffffffffffffff ?
by Spooky (Beadle) on Oct 02, 2009 at 16:11 UTC
    ..thanks so much!