Xenofur has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks,

I am currently working on a project where i query an API, which then gives me back various informations about objects in an xml sheet. These informations i then store in a mysql database for caching and further processing.

My problem comes with one attribute of said objects that codifies various related attributes into a single bitmask. Due to the way the API works, this bitmask is presented as a decimal integer in string form. An example would be this:
576458570460036993
(This is roughly as big as it gets.)

Since the mysql database does not seem to be capable of storing integers of that size (Even when the column is set to integer of size 100.), i was forced to store the numbers as raw text. However, to make a long story short, i cannot seem to find a way to extract that string from the database in a way that allows me to tell perl to treat it as a number, so i can perform binary operations on it to check against the various attributes stored in the bitmask.

Am i doing something horribly wrong, overlooking something, or is there simply no easy way to make this possible?
  • Comment on How to deal with a 59-bit bitmask that is given in decimal integer string form?

Replies are listed 'Best First'.
Re: How to deal with a 59-bit bitmask that is given in decimal integer string form?
by jethro (Monsignor) on Jul 12, 2008 at 13:49 UTC
    Your number is too big for perls integer arithmetic, so it is stored as floating point with its inherent fuzzyness.

    You might use a math module like bignum:

    perl -e '$x="576458570460036993"; print ($x & 15);' 15 perl -e 'use bignum; $x="576458570460036993"; print ($x & 15);' 1
      Awesome, exactly what i needed. Thanks a lot for the quick and simple answer!