http://qs1969.pair.com?node_id=11135535


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

The answer to your question is hidden in the documentation for Integer Arithmetic. You need use integer; if you want your result as a signed integer. (By default it is treated as an unsigned integer.) Note also, that your << 28 assumes that your perl is compiled for 32-bit integers.
Bill

Replies are listed 'Best First'.
Re^2: Difference between Perl and Java for << operator?
by syphilis (Archbishop) on Jul 31, 2021 at 10:25 UTC
    Note also, that your << 28 assumes that your perl is compiled for 32-bit integers

    Well spotted - if you want to use the perl sub that the OP provided then:
    1) you will need to be running under the use integer pragma;
    and
    2) you will also need to be running a perl that was built with 32-bit integers.

    However, as has also been demonstrated, there are ways to obtain the desired result by doing a 0xFFFFFFFF << 28, that will work on both 32-bit integer and 64-bit integer builds.

    Cheers,
    Rob
Re^2: Difference between Perl and Java for << operator?
by eyepopslikeamosquito (Archbishop) on Jul 31, 2021 at 07:33 UTC