http://www.perlmonks.org?node_id=965361


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
    Hey Eliya,

    Thanks for the quick response. Your solutions look promising. I especially like the one where you turn the hex string in a ASCII bit string. I will try this with my code and test it with the switch. I will let you know how things went.