Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Implementing a signed/sign-propagating right bitwise shift

by LonelyPilgrim (Beadle)
on Feb 16, 2012 at 18:50 UTC ( [id://954324]=note: print w/replies, xml ) Need Help??


in reply to Implementing a signed/sign-propagating right bitwise shift

Thanks for all the helpful replies. Another little question that's bugging me (I'm not sure if anybody will see this down here or not): does my function presume endian-ness of one form or another? Or does that even matter? Whether big-endian or little-endian, the leftmost bit of the leftmost byte will be the sign bit, correct? Will the endian-ness of the integer affect how it is shifted? It doesn't appear to so far, since even on my little-endian Win32 system, I get the correct end result. And it doesn't seem to matter if I remove the ">" from my pack and unpack there at the end -- I get the correct result. As I said, my understanding of the binary system is still pretty new.

  • Comment on Re: Implementing a signed/sign-propagating right bitwise shift

Replies are listed 'Best First'.
Re^2: Implementing a signed/sign-propagating right bitwise shift
by jethro (Monsignor) on Feb 17, 2012 at 10:00 UTC

    endianness may become important if you store numbers as binary data in a string (with the pack function) or on disk. It is important in languages like C that allow you to use the memory cells your integers are stored in as any other data type.

    Perl (and many other interpreted languages) don't allow this. You can't access the memory cells of your variables directly. If you use your integer variable as a string a conversion will be done by the interpreter. '>>' and other functions know the endianness of the system and use it. That is even true for C.

    Note that you can specify endianness when you use the pack function.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found