billl@oakhill.UUCP (Bill Ledbetter) (03/19/90)
I seem to be having problems with the unsigned pack/unpack operations. I am running: $Header: perly.c,v 3.0.1.4 90/02/28 18:06:41 lwall Locked $ Patch level: 15 on a sun3 with SunOS 3.5. The following script shows the problem: # ------------------------------------ #!/usr/local/perl3 -s $[ = 1; $lw[1] = hex("01234567"); $lw[2] = hex("89abcdef"); $binI = pack("I2", @lw); @newI = unpack("I2", $binI); # Prints out "01234567 00000000" printf "%08x %08x\n", $newI[1], $newI[2]; $bini = pack("i2", @lw); @newi = unpack("i2", $bini); # Prints out "01234567 89abcdef" printf "%08x %08x\n", $newi[1], $newi[2]; ------ This seems to be counter-intuitive. Is this a bug, or am I doing something really stupid... --------------------------------------------------------------------------- Bill Ledbetter Motorola Inc. MD OE37 email: cs.utexas.edu!oakhill!billl 6501 William Cannon Dr. West Austin, TX 78735-8598
piet@cs.ruu.nl (Piet van Oostrum) (03/19/90)
In article <3105@jupiter.oakhill.UUCP>, billl@oakhill (Bill Ledbetter) writes:
`I seem to be having problems with the unsigned pack/unpack operations. I
`am running:
`
` $Header: perly.c,v 3.0.1.4 90/02/28 18:06:41 lwall Locked $
` Patch level: 15
`
` on a sun3 with SunOS 3.5.
Well, that might be a Sunny problem, because on both HCX and HP the script
runs OK.
--
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31-30-531806 Uucp: uunet!mcsun!ruuinf!piet
Telefax: +31-30-513791 Internet: piet@cs.ruu.nl (*`Pete')
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/20/90)
In article <3105@jupiter.oakhill.UUCP> billl@oakhill.UUCP (Bill Ledbetter) writes:
: $[ = 1;
:
: $lw[1] = hex("01234567");
: $lw[2] = hex("89abcdef");
: $binI = pack("I2", @lw);
: @newI = unpack("I2", $binI);
:
: # Prints out "01234567 00000000"
: printf "%08x %08x\n", $newI[1], $newI[2];
:
: $bini = pack("i2", @lw);
: @newi = unpack("i2", $bini);
:
: # Prints out "01234567 89abcdef"
: printf "%08x %08x\n", $newi[1], $newi[2];
:
: ------
:
: This seems to be counter-intuitive. Is this a bug, or am I doing something
: really stupid...
It's a bug on someone's part--but we're not sure who. It seems that Sun
won't let you cast a negative floating point number to an unsigned integer.
While there's something to be said for this viewpoint, compatibility with
other machines ain't one of them. I'm working on the problem.
Larry