rjbell4 has asked for the wisdom of the Perl Monks concerning the following question:
As a work around, I wind up manipulating the number as two 32-bit quantities. However, this is much slower, and, IMNSHO, quite ridiculous.
Below is a script and it's output illustrating what I am describing:
$ ./foo.pl A) 0xfffffc0123456789 (should be 0xfffffc0123456789) B) 0xfffffc0123456800 (should be 0xfffffc0123456789) C) 0xfffffc0123456789 (should be 0xfffffc0123456789) D) 0xfffffc0123456800 (should be 0xfffffc0123456788 or maybe 0xfffffc0 +123456790) E) 0x23456789 (should be 0x23456789) F) 0xfffffc01 (should be 0xfffffc01) G) Comparing 0xfffffc0123456789 to 0xfffffc0123456785: 1) 0 (should be 1) 2) 0 (should be -1) 3) 0 (should be 0) $ $ cat foo.pl #!/usr/local/bin/perl $a = 0xfffffc0123456789; printf "A) %#x (should be 0xfffffc0123456789)\n", $a; $str = "0xfffffc0123456789"; printf "B) %#x (should be 0xfffffc0123456789)\n", hex($str); $b = unpack "Q", (pack "L2", hex(substr($str, 10)), hex(substr($str, 2 +, 8))); printf "C) %#x (should be 0xfffffc0123456789)\n", $b; printf "D) %#x (should be 0xfffffc0123456788 or maybe 0xfffffc01234567 +90)\n", $a - 1; printf "E) %#x (should be 0x23456789)\n", $a & 0xffffffff; printf "F) %#x (should be 0xfffffc01)\n", $a >> 32; $b = 0xfffffc0123456785; printf "G) Comparing %#x to %#x:\n", $a, $b; printf " 1) %d (should be 1)\n", $a <=> $b; printf " 2) %d (should be -1)\n", $b <=> $a; printf " 3) %d (should be 0)\n", $a <=> $a; $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Manipulating 64-bit values
by Elian (Parson) on Jun 04, 2002 at 20:31 UTC | |
by rjbell4 (Novice) on Jun 05, 2002 at 00:25 UTC | |
|
Re: Manipulating 64-bit values
by samtregar (Abbot) on Jun 04, 2002 at 21:00 UTC | |
by rjbell4 (Novice) on Jun 05, 2002 at 00:27 UTC |