in reply to Re: Re: how to unpack a big-endian signed short integer
in thread how to unpack a big-endian signed short integer

Sorry. I misread that. Try this...

print unpack 's', pack 'S', unpack 'n', $n;

Unpacking it with 'n' will handle the big-endianess without dropping bits. Repacking it with 'S' should likewise not drop anything, but will get it into a format that 's' will correctly unpack.

I would use 'n' in the composite unpack and then

sub utos16{ unpack 's', pack 'S', $_[0] }

to retrieve the signedness afterwards.

(Note: Please check I got that right:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!