Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How do I unpack a signed long in big endian?

by aspangler (Initiate)
on Jun 21, 2002 at 02:52 UTC ( [id://176216]=perlquestion: print w/replies, xml ) Need Help??

aspangler has asked for the wisdom of the Perl Monks concerning the following question:

I need something like
( $val ) = unpack( "N", $raw )
except that the number can be negative.

The code should be platform neutral.

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I unpack a signed long in big endian?
by Anonymous Monk on Jun 21, 2002 at 03:50 UTC
    $val = unpack( "N", $raw ^ "\x80\0\0\0" ) - ( 1 << 31 );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://176216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found