in reply to Bit fiddling madness
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bit fiddling madness
by Athanasius (Cardinal) on Feb 11, 2014 at 15:51 UTC | |
by BrowserUk (Patriarch) on Feb 11, 2014 at 16:06 UTC | |
by mbethke (Hermit) on Feb 11, 2014 at 16:36 UTC | |
by sn1987a (Curate) on Feb 11, 2014 at 16:07 UTC |