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

Thanks for the suggestion. However the values I'm reading are signed, i.e. signed, big-endian 16-bit integers. There doesn't seem to be a an appropriate format character for this. Bummer!

-- Robin Bowes | http://robinbowes.com
  • Comment on Re: Re: how to unpack a big-endian signed short integer

Replies are listed 'Best First'.
Re: Re: Re: how to unpack a big-endian signed short integer
by BrowserUk (Patriarch) on Oct 15, 2003 at 20:06 UTC

    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!