in reply to Re^2: Bitwise AND with large numbers
in thread Bitwise AND with large numbers
This works fine for me:
use Math::BigInt; my $switchPortNumber = 2; # 32 Character hex string from switch my $hexstring = Math::BigInt->new('0x40000000000000000000000000000000' +); my $mask = (Math::BigInt->new('0x80000000000000000000000000000000') >> + $switchPortNumber); my $result = ($hexstring & $mask) > 0;
Another approach would be to turn it into an ASCII bitstring, in which case you can use a simple substr() instead of the AND masking
my $bitstring = unpack('B*', pack('H*', '40000000000000000000000000000 +000')); my $result = substr($bitstring, $switchPortNumber, 1) eq '1';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Bitwise AND with large numbers
by mdej (Initiate) on Apr 20, 2012 at 08:20 UTC |
In Section
Seekers of Perl Wisdom