in reply to Is there a 64-bit hex()?

When in doubt, try pack or unpack. perlpacktut is a nice introduction.

You can convert it to a binary string, but not to a portably to an integer, because it simply doesn't fit into the CPU registers.

Replies are listed 'Best First'.
Re^2: Is there a 64-bit hex()?
by Porculus (Hermit) on Feb 10, 2009 at 08:55 UTC

    But the return value of hex() usually isn't an integer in the CPU-register sense!

    And even when it is, plenty of languages can handle 64-bit integers on 32-bit hardware. There's no law that states that all variables must fit into a single CPU register. (How would strings ever work if that were the case?)

    This kind of thing can be done portably. Therefore, it is legitimate to be puzzled about why Perl complains about it.

      But the return value of hex() usually isn't an integer in the CPU-register sense!

      Right, it's an IV, which points to a native integer.

      And even when it is, plenty of languages can handle 64-bit integers on 32-bit hardware.

      With the appropriate amount of emulation, yes.

      Note that perl is written in C, and I don't think that C makes any guarantees for the availability of a 64 bit integer type. Many other language implementations "solve" this problem by ignoring platforms or compilers that don't do what they want, but perl's focus is usually stronger on portability.

      There's no law that states that all variables must fit into a single CPU register. (How would strings ever work if that were the case?)

      Sure there's no such law, but if they don't, they are generally not as efficient.

        Note that perl is written in C
        True.
        I don't think that C makes any guarantees for the availability of a 64 bit integer type.
        True. In fact, considering the age of C, I don't even think 32 bit integers are garanteed.
        Many other language implementations "solve" this problem by ignoring platforms or compilers that don't do what they want, but perl's focus is usually stronger on portability.
        ... true, but Perl can be compiled to have 64-bit integers even if the underlaying hardware is 32 bits. It's actually the C compiler that determines whether you can have 64 bit integers or not. And many modern C compilers, including gcc, allow for this. (But it has worked the other way around as well. About a dozen years ago, I worked on a 64-bit SUN platform, but the then version of gcc couldn't deal with 64 bits).

        Note also that even if your hardware is 32 bits, and you don't compile Perl to have 64 bit integers, your Perl integers still aren't limited to 32 bits. If an integer value exceeds 32 bits, Perl silently upgrades it to a float, and will give "integers" up to 64 bits. If the value exceeds about 53 bits, the "integers" aren't exact any more, they will have some losses in their least significant bits (which may mean that if you add 1 to such an integer, it doesn't change value).

Re^2: Is there a 64-bit hex()?
by kornerr (Novice) on Feb 10, 2009 at 07:56 UTC
    I need a hex value.
      You have a hex value. What do you want to do with it?

      Or asked differently - if string of the form 0x00ff... isn't a hex value for you, what is a hex value in your opinion?