in reply to Bitwise AND with large numbers
You can do bitwise AND with strings, too (in which case there's no size limitation).
So, convert your hex string and your number to binary strings using pack (e.g. pack "H*", $hexstring for the hex string), pad the shorter one to the length of the longer one (with \0 or \xff, depending on the desired semantics), AND (&) both strings, and convert the result back to whatever you like (e.g. hex string).
The details somewhat depend on what exactly you need, so if you provide sample inputs and desired result, someone will surely come up with actual code...
Otherwise, if you want to stick with Math::Big*, there is from_hex().
Re^2: Bitwise AND with large numbers by mdej (Initiate) on Apr 16, 2012 at 16:56 UTC 
Hi,
Thank you for your quick reactions ;)
Using Math::BigInt or pack I unfortunately still get an integer overflow. I'm probably doing something wrong but don't see what. Sorry if this is to much of a newbie question.
A little more context: The hexstring comes from a switch. I want to use the hexstring to determine if a switchport is member of a specific VLAN.
The code I have so far is:
my $switchPortNumber = 2;
# 32 Character hex string from switch
my $hexstring = hex '40000000000000000000000000000000';
my $mask = (0x80000000000000000000000000000000 >> $switchPortNumber);
my $result = ($hexstring & $mask) > 0;
In this case only the first port is a member and the second port is NOT a member. Therefore the $result should be 0
If possible I would like to stick to the default Perl modules.
Thanks again for all the help so far.
 [reply] [d/l] 

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';
 [reply] [d/l] [select] 

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.
 [reply] 
