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

Hello, I need a data structure that can hold 64 bits of info so I can do & and | and other fun stuff to it... but my build of perl/operating system/processor doesn't support this kind of thing... right? Whats the best way to do this?

Edit kudra, 2002-02-26 Changed title

  • Comment on Need data struct that can hold 64 bits of info (was: bitboards in perl)

Replies are listed 'Best First'.
Re: bitboards in perl
by blakem (Monsignor) on Feb 24, 2002 at 06:04 UTC
Re: bitboards in perl
by YuckFoo (Abbot) on Feb 24, 2002 at 16:23 UTC
    You can also use strings of any length. See perlman:perlop, refer to section 'Bitwise String Operators'. Not as effecient as vectors and probably slower, but 'easier'.

    YuckFoo

Re: bitboards in perl
by justinNEE (Monk) on Feb 24, 2002 at 15:57 UTC
    perlfunc on vec() : "BITS therefore specifies the number of bits that are reserved for each element in the bit vector. This must be a power of two from 1 to 32 (or 64, if your platform supports that). " I guess I could just use two 32 bit elements and make my own bitwise operators...
      ...reserved for each element in the bit vector.

      You were wanting 64 bits, so each is one bit wide. This is 32-bit perl:

      $ perl -e 'vec( $foo, 63, 1) = 1; print unpack( "b64",$foo),$/' 0000000000000000000000000000000000000000000000000000000000000001
      or, if you prefer your high order bits printed on the left,
      $ perl -e 'vec( $foo, 63, 1) = 1; print scalar reverse(unpack "b64",$f +oo),$/' 1000000000000000000000000000000000000000000000000000000000000000
      The bitwise operators work on vec() strings

      After Compline,
      Zaxo