I notice that Net/CIDR/Lookup.pm has "use integer"
According to Shift Operators:
Note that both << and >> in Perl are implemented directly using << and >> in C. If use integer (see Integer Arithmetic) is in force then signed C integers are used."This means that right shifts will be sign extended. Anything with the msb set will be sign extended and remain negative.
$ perl -E 'use integer; say 0x80000000 >> 31' -1
RichardK's suggestion above would avoid this issue.
In reply to Re: Bit fiddling madness
by sn1987a
in thread Bit fiddling madness
by mbethke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |