Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Difference between Perl and Java for << operator?

by LanX (Saint)
on Jul 29, 2021 at 23:03 UTC ( [id://11135507]=note: print w/replies, xml ) Need Help??


in reply to Difference between Perl and Java for << operator?

Don't know much about Java, but

> I have this bit of Java code, which is known to work as-expected:

> RESULT: -268435456

How can a negative result be considered expected?

I think you should take care that both sides are unsigned integers of same size.

FWIW I don't get your Perl result

DB<16> say $x= 0xFFFFFFFF << 28 1152921504338411520

so 64bit Perl seems to matter too.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Difference between Perl and Java for << operator?
by GrandFather (Saint) on Jul 30, 2021 at 04:00 UTC

    It's an expected result if you assume signed 32 bit integer variables and your code is predicated on that assumption.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      as I said

      > > take care that both sides are unsigned integers of same size.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        All integers are signed in Java. or at least they were a decade ago when I used it. It's one of the annoyances of the language.

Log In?
Username:
Password:

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

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

    No recent polls found